@@ -32,8 +32,6 @@ |
||
32 | 32 | * ) |
33 | 33 | * ) |
34 | 34 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
35 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | - * set to true, it will be stored as an INT |
|
37 | 35 | */ |
38 | 36 | public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
39 | 37 | { |
@@ -3,114 +3,114 @@ |
||
3 | 3 | class EE_WP_Post_Status_Field extends EE_Enum_Text_Field |
4 | 4 | { |
5 | 5 | |
6 | - protected $_wp_post_stati; |
|
6 | + protected $_wp_post_stati; |
|
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * constructor |
|
11 | - * |
|
12 | - * @param string $table_column column on table |
|
13 | - * @param string $nicename nice name for column(field) |
|
14 | - * @param bool $nullable is this field nullable |
|
15 | - * @param string $default_value default status |
|
16 | - * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
17 | - * they can be registered via this property. The format of the array should be |
|
18 | - * as follows: array( |
|
19 | - * 'status_reference' => array( |
|
20 | - * 'label' => __('Status Reference Label', 'event_espresso') |
|
21 | - * 'public' => true, //'Whether posts of this status should be shown on the |
|
22 | - * frontend of the site' |
|
23 | - * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
24 | - * excluded from wp searches' |
|
25 | - * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
26 | - * in queries for the admin "all" view in list table views. |
|
27 | - * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
28 | - * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
29 | - * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
30 | - * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
31 | - * on the admin screen( or you won't see your status count ). |
|
32 | - * ) |
|
33 | - * ) |
|
34 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
35 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | - * set to true, it will be stored as an INT |
|
37 | - */ |
|
38 | - public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
39 | - { |
|
40 | - $this->_register_new_stati($new_stati); |
|
41 | - $this->_set_allowed_enum_values(); |
|
42 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
43 | - } |
|
9 | + /** |
|
10 | + * constructor |
|
11 | + * |
|
12 | + * @param string $table_column column on table |
|
13 | + * @param string $nicename nice name for column(field) |
|
14 | + * @param bool $nullable is this field nullable |
|
15 | + * @param string $default_value default status |
|
16 | + * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
17 | + * they can be registered via this property. The format of the array should be |
|
18 | + * as follows: array( |
|
19 | + * 'status_reference' => array( |
|
20 | + * 'label' => __('Status Reference Label', 'event_espresso') |
|
21 | + * 'public' => true, //'Whether posts of this status should be shown on the |
|
22 | + * frontend of the site' |
|
23 | + * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
24 | + * excluded from wp searches' |
|
25 | + * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
26 | + * in queries for the admin "all" view in list table views. |
|
27 | + * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
28 | + * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
29 | + * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
30 | + * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
31 | + * on the admin screen( or you won't see your status count ). |
|
32 | + * ) |
|
33 | + * ) |
|
34 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
35 | + * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | + * set to true, it will be stored as an INT |
|
37 | + */ |
|
38 | + public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
39 | + { |
|
40 | + $this->_register_new_stati($new_stati); |
|
41 | + $this->_set_allowed_enum_values(); |
|
42 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * This registers any new statuses sent via the $new_stati array on construct |
|
48 | - * |
|
49 | - * @access protected |
|
50 | - * @param array $new_stati statuses |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - protected function _register_new_stati($new_stati) |
|
54 | - { |
|
46 | + /** |
|
47 | + * This registers any new statuses sent via the $new_stati array on construct |
|
48 | + * |
|
49 | + * @access protected |
|
50 | + * @param array $new_stati statuses |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + protected function _register_new_stati($new_stati) |
|
54 | + { |
|
55 | 55 | |
56 | - foreach ((array) $new_stati as $status_key => $status_args) { |
|
57 | - $args = array( |
|
58 | - 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
59 | - 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
60 | - 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
61 | - 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
62 | - 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
63 | - 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
64 | - ); |
|
65 | - register_post_status($status_key, $status_args); |
|
66 | - } |
|
67 | - } |
|
56 | + foreach ((array) $new_stati as $status_key => $status_args) { |
|
57 | + $args = array( |
|
58 | + 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
59 | + 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
60 | + 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
61 | + 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
62 | + 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
63 | + 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
64 | + ); |
|
65 | + register_post_status($status_key, $status_args); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
72 | - * |
|
73 | - * @access protected |
|
74 | - * @regurn void |
|
75 | - */ |
|
76 | - protected function _set_allowed_enum_values() |
|
77 | - { |
|
78 | - // first let's get the post_statuses |
|
79 | - global $wp_post_statuses; |
|
80 | - $this->_wp_post_stati = $wp_post_statuses; |
|
70 | + /** |
|
71 | + * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
72 | + * |
|
73 | + * @access protected |
|
74 | + * @regurn void |
|
75 | + */ |
|
76 | + protected function _set_allowed_enum_values() |
|
77 | + { |
|
78 | + // first let's get the post_statuses |
|
79 | + global $wp_post_statuses; |
|
80 | + $this->_wp_post_stati = $wp_post_statuses; |
|
81 | 81 | |
82 | - foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
83 | - $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
84 | - } |
|
85 | - } |
|
82 | + foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
83 | + $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Before calling parent, first double-checks our list of acceptable post |
|
89 | - * types is up-to-date |
|
90 | - * |
|
91 | - * @param string $value_inputted_for_field_on_model_object |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
95 | - { |
|
96 | - $this->_set_allowed_enum_values(); |
|
97 | - return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
98 | - } |
|
87 | + /** |
|
88 | + * Before calling parent, first double-checks our list of acceptable post |
|
89 | + * types is up-to-date |
|
90 | + * |
|
91 | + * @param string $value_inputted_for_field_on_model_object |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
95 | + { |
|
96 | + $this->_set_allowed_enum_values(); |
|
97 | + return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | 101 | |
102 | - // helper methods for getting various $wp_post_statuses stuff. |
|
102 | + // helper methods for getting various $wp_post_statuses stuff. |
|
103 | 103 | |
104 | - /** |
|
105 | - * This just returns the status object for the given status |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
109 | - * @param string $status What status object you want |
|
110 | - * @return std_object the status object or FALSE if it doesn't exist. |
|
111 | - */ |
|
112 | - public function get_status_object($status) |
|
113 | - { |
|
114 | - return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
115 | - } |
|
104 | + /** |
|
105 | + * This just returns the status object for the given status |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
109 | + * @param string $status What status object you want |
|
110 | + * @return std_object the status object or FALSE if it doesn't exist. |
|
111 | + */ |
|
112 | + public function get_status_object($status) |
|
113 | + { |
|
114 | + return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
115 | + } |
|
116 | 116 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $this->_wp_post_stati = $wp_post_statuses; |
81 | 81 | |
82 | 82 | foreach ($this->_wp_post_stati as $post_status => $args_object) { |
83 | - $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
83 | + $this->_allowed_enum_values[$post_status] = $args_object->label; |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
@@ -111,6 +111,6 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function get_status_object($status) |
113 | 113 | { |
114 | - return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
114 | + return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false; |
|
115 | 115 | } |
116 | 116 | } |
@@ -44,19 +44,33 @@ discard block |
||
44 | 44 | |
45 | 45 | private $_group_by_sql; |
46 | 46 | |
47 | + /** |
|
48 | + * @param string $limit_sql |
|
49 | + */ |
|
47 | 50 | public function set_limit_sql($limit_sql) |
48 | 51 | { |
49 | 52 | $this->_limit_sql = $limit_sql; |
50 | 53 | } |
51 | 54 | |
55 | + /** |
|
56 | + * @param string $order_by_sql |
|
57 | + */ |
|
52 | 58 | public function set_order_by_sql($order_by_sql) |
53 | 59 | { |
54 | 60 | $this->_order_by_sql = $order_by_sql; |
55 | 61 | } |
62 | + |
|
63 | + /** |
|
64 | + * @param string $group_by_sql |
|
65 | + */ |
|
56 | 66 | public function set_group_by_sql($group_by_sql) |
57 | 67 | { |
58 | 68 | $this->_group_by_sql = $group_by_sql; |
59 | 69 | } |
70 | + |
|
71 | + /** |
|
72 | + * @param string $having_sql |
|
73 | + */ |
|
60 | 74 | public function set_having_sql($having_sql) |
61 | 75 | { |
62 | 76 | $this->_having_sql = $having_sql; |
@@ -81,7 +95,6 @@ discard block |
||
81 | 95 | * |
82 | 96 | * @param type $model_included_name |
83 | 97 | * @param type $join_sql |
84 | - * @param type $data_types |
|
85 | 98 | */ |
86 | 99 | public function __construct($model_included_name = array(), $join_sql = '') |
87 | 100 | { |
@@ -14,141 +14,141 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...") |
16 | 16 | */ |
17 | - private $_join_sql; |
|
17 | + private $_join_sql; |
|
18 | 18 | /** |
19 | 19 | * |
20 | 20 | * @var array stating all the models that have been included thus far,so we don't get duplicates. |
21 | 21 | * Keys are the model relation chains to them from the queried model |
22 | 22 | * (eg, "Registration.Transaction.Payment"), and valuesare model names (eg "Payment") |
23 | 23 | */ |
24 | - private $_models_included; |
|
24 | + private $_models_included; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * After we've acquired all the data types, we can create this sql. |
28 | 28 | * @var string |
29 | 29 | */ |
30 | - private $_where_sql; |
|
30 | + private $_where_sql; |
|
31 | 31 | /** |
32 | 32 | * Full join sql. Eg, in a select query, that's everything after the "FROM", and before the "WHERE", so it includes |
33 | 33 | * the declaration of the main model's tables, and then appends all the joining sql to other models |
34 | 34 | * @var string |
35 | 35 | */ |
36 | - private $_main_join_sql; |
|
36 | + private $_main_join_sql; |
|
37 | 37 | |
38 | 38 | |
39 | - private $_limit_sql; |
|
39 | + private $_limit_sql; |
|
40 | 40 | |
41 | - private $_order_by_sql; |
|
41 | + private $_order_by_sql; |
|
42 | 42 | |
43 | - private $_having_sql; |
|
43 | + private $_having_sql; |
|
44 | 44 | |
45 | - private $_group_by_sql; |
|
45 | + private $_group_by_sql; |
|
46 | 46 | |
47 | - public function set_limit_sql($limit_sql) |
|
48 | - { |
|
49 | - $this->_limit_sql = $limit_sql; |
|
50 | - } |
|
47 | + public function set_limit_sql($limit_sql) |
|
48 | + { |
|
49 | + $this->_limit_sql = $limit_sql; |
|
50 | + } |
|
51 | 51 | |
52 | - public function set_order_by_sql($order_by_sql) |
|
53 | - { |
|
54 | - $this->_order_by_sql = $order_by_sql; |
|
55 | - } |
|
56 | - public function set_group_by_sql($group_by_sql) |
|
57 | - { |
|
58 | - $this->_group_by_sql = $group_by_sql; |
|
59 | - } |
|
60 | - public function set_having_sql($having_sql) |
|
61 | - { |
|
62 | - $this->_having_sql = $having_sql; |
|
63 | - } |
|
64 | - public function get_limit_sql() |
|
65 | - { |
|
66 | - return $this->_limit_sql; |
|
67 | - } |
|
68 | - public function get_order_by_sql() |
|
69 | - { |
|
70 | - return $this->_order_by_sql; |
|
71 | - } |
|
72 | - public function get_group_by_sql() |
|
73 | - { |
|
74 | - return $this->_group_by_sql; |
|
75 | - } |
|
76 | - public function get_having_sql() |
|
77 | - { |
|
78 | - return $this->_having_sql; |
|
79 | - } |
|
52 | + public function set_order_by_sql($order_by_sql) |
|
53 | + { |
|
54 | + $this->_order_by_sql = $order_by_sql; |
|
55 | + } |
|
56 | + public function set_group_by_sql($group_by_sql) |
|
57 | + { |
|
58 | + $this->_group_by_sql = $group_by_sql; |
|
59 | + } |
|
60 | + public function set_having_sql($having_sql) |
|
61 | + { |
|
62 | + $this->_having_sql = $having_sql; |
|
63 | + } |
|
64 | + public function get_limit_sql() |
|
65 | + { |
|
66 | + return $this->_limit_sql; |
|
67 | + } |
|
68 | + public function get_order_by_sql() |
|
69 | + { |
|
70 | + return $this->_order_by_sql; |
|
71 | + } |
|
72 | + public function get_group_by_sql() |
|
73 | + { |
|
74 | + return $this->_group_by_sql; |
|
75 | + } |
|
76 | + public function get_having_sql() |
|
77 | + { |
|
78 | + return $this->_having_sql; |
|
79 | + } |
|
80 | 80 | /** |
81 | 81 | * |
82 | 82 | * @param type $model_included_name |
83 | 83 | * @param type $join_sql |
84 | 84 | * @param type $data_types |
85 | 85 | */ |
86 | - public function __construct($model_included_name = array(), $join_sql = '') |
|
87 | - { |
|
88 | - $this->_models_included = $model_included_name; |
|
89 | - $this->_join_sql = $join_sql; |
|
90 | - } |
|
86 | + public function __construct($model_included_name = array(), $join_sql = '') |
|
87 | + { |
|
88 | + $this->_models_included = $model_included_name; |
|
89 | + $this->_join_sql = $join_sql; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Merges info from the other EEM_Related_Model_Info_Carrier into this one. |
94 | 94 | * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier |
95 | 95 | */ |
96 | - public function merge($other_model_query_info_carrier) |
|
97 | - { |
|
98 | - if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) { |
|
99 | - $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
100 | - $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier); |
|
101 | - $this->_join_sql .= $other_model_query_info_carrier->_join_sql; |
|
102 | - } |
|
103 | - // otherwise don't merge our data. |
|
104 | - // yes, this means that we must immediately merge any model data into our grand list |
|
105 | - // as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier |
|
106 | - // which is carrying info from two models WHERE one is already included but the other is NOT |
|
107 | - } |
|
96 | + public function merge($other_model_query_info_carrier) |
|
97 | + { |
|
98 | + if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) { |
|
99 | + $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
100 | + $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier); |
|
101 | + $this->_join_sql .= $other_model_query_info_carrier->_join_sql; |
|
102 | + } |
|
103 | + // otherwise don't merge our data. |
|
104 | + // yes, this means that we must immediately merge any model data into our grand list |
|
105 | + // as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier |
|
106 | + // which is carrying info from two models WHERE one is already included but the other is NOT |
|
107 | + } |
|
108 | 108 | /** |
109 | 109 | * Checks whether or not we have already included all the models mentione din $model_names on the query info varrier |
110 | 110 | * @param array $model_names just like EE_MOdel_QUery_Info_Carrier::_models_included: keys are model chain paths, values are the model names only |
111 | 111 | * @return boolean |
112 | 112 | */ |
113 | - protected function _have_already_included_one_of_these_models($model_names) |
|
114 | - { |
|
115 | - foreach ($this->_models_included as $model_relation_path => $model_included) { |
|
116 | - if (array_key_exists($model_relation_path, $model_names)) { |
|
117 | - return true; |
|
118 | - } |
|
119 | - } |
|
120 | - return false; |
|
121 | - } |
|
113 | + protected function _have_already_included_one_of_these_models($model_names) |
|
114 | + { |
|
115 | + foreach ($this->_models_included as $model_relation_path => $model_included) { |
|
116 | + if (array_key_exists($model_relation_path, $model_names)) { |
|
117 | + return true; |
|
118 | + } |
|
119 | + } |
|
120 | + return false; |
|
121 | + } |
|
122 | 122 | /** |
123 | 123 | * Array keys are model names, values are "model relation paths". See EE_Model_Query_Info_Carrier::_models_included for details |
124 | 124 | * @return array like EE_Model_Query_Info_Carrier::_models_included |
125 | 125 | */ |
126 | - public function get_model_names_included() |
|
127 | - { |
|
128 | - return $this->_models_included; |
|
129 | - } |
|
126 | + public function get_model_names_included() |
|
127 | + { |
|
128 | + return $this->_models_included; |
|
129 | + } |
|
130 | 130 | /** |
131 | 131 | * sets the $where_sql for later use from client code |
132 | 132 | * @param string $where_sql |
133 | 133 | */ |
134 | - public function set_where_sql($where_sql) |
|
135 | - { |
|
136 | - $this->_where_sql = $where_sql; |
|
137 | - } |
|
138 | - public function get_where_sql() |
|
139 | - { |
|
140 | - return $this->_where_sql; |
|
141 | - } |
|
134 | + public function set_where_sql($where_sql) |
|
135 | + { |
|
136 | + $this->_where_sql = $where_sql; |
|
137 | + } |
|
138 | + public function get_where_sql() |
|
139 | + { |
|
140 | + return $this->_where_sql; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Gets the SQL for joining the main model to other models involves in the query, which was set earlier on |
145 | 145 | * the EE_Model_Query_info_Carrier by calling set_main_model_join_sql() |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - public function get_main_model_join_sql() |
|
149 | - { |
|
150 | - return $this->_main_join_sql; |
|
151 | - } |
|
148 | + public function get_main_model_join_sql() |
|
149 | + { |
|
150 | + return $this->_main_join_sql; |
|
151 | + } |
|
152 | 152 | |
153 | 153 | |
154 | 154 | /** |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * after the FROM and before the WHERE.) |
159 | 159 | * @param string $join_sql |
160 | 160 | */ |
161 | - public function set_main_model_join_sql($join_sql) |
|
162 | - { |
|
163 | - $this->_main_join_sql = $join_sql; |
|
164 | - } |
|
165 | - public function get_full_join_sql() |
|
166 | - { |
|
167 | - return $this->_main_join_sql . $this->_join_sql; |
|
168 | - } |
|
161 | + public function set_main_model_join_sql($join_sql) |
|
162 | + { |
|
163 | + $this->_main_join_sql = $join_sql; |
|
164 | + } |
|
165 | + public function get_full_join_sql() |
|
166 | + { |
|
167 | + return $this->_main_join_sql . $this->_join_sql; |
|
168 | + } |
|
169 | 169 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function merge($other_model_query_info_carrier) |
97 | 97 | { |
98 | 98 | if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) { |
99 | - $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
99 | + $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
100 | 100 | $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier); |
101 | 101 | $this->_join_sql .= $other_model_query_info_carrier->_join_sql; |
102 | 102 | } |
@@ -164,6 +164,6 @@ discard block |
||
164 | 164 | } |
165 | 165 | public function get_full_join_sql() |
166 | 166 | { |
167 | - return $this->_main_join_sql . $this->_join_sql; |
|
167 | + return $this->_main_join_sql.$this->_join_sql; |
|
168 | 168 | } |
169 | 169 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * creates join statement FROM primary table |
55 | 55 | * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
56 | 56 | * |
57 | - * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
57 | + * @param string $primary_table_alias_with_model_chain_prefix |
|
58 | 58 | * @return string of SQL |
59 | 59 | */ |
60 | 60 | public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
@@ -78,6 +78,7 @@ discard block |
||
78 | 78 | * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
79 | 79 | * " LEFT JOIN primary_table AS Primary ON ...". |
80 | 80 | * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
81 | + * @param string $secondary_table_alias_with_model_chain_prefix |
|
81 | 82 | * @return string |
82 | 83 | */ |
83 | 84 | public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
@@ -8,118 +8,118 @@ |
||
8 | 8 | */ |
9 | 9 | class EE_Secondary_Table extends EE_Table_Base |
10 | 10 | { |
11 | - protected $_extra_join_conditions; |
|
11 | + protected $_extra_join_conditions; |
|
12 | 12 | |
13 | - /** |
|
14 | - * |
|
15 | - * @global type $wpdb |
|
16 | - * @param string $table_name with or without wpdb prefix |
|
17 | - * @param string $pk_column name of primary key column on THIS table |
|
18 | - * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | - * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | - * or whether each site on a multisite install has a copy of this table |
|
22 | - */ |
|
23 | - public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | - { |
|
25 | - $this->_fk_on_table = $fk_column; |
|
26 | - $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | - parent::__construct($table_name, $pk_column, $global); |
|
28 | - } |
|
29 | - public function get_fk_on_table() |
|
30 | - { |
|
31 | - return $this->_fk_on_table; |
|
32 | - } |
|
33 | - public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | - { |
|
35 | - $this->_table_to_join_with = $table; |
|
36 | - } |
|
37 | - /** |
|
38 | - * |
|
39 | - * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | - * the end of the join statement with the primary table |
|
41 | - */ |
|
42 | - public function get_extra_join_conditions() |
|
43 | - { |
|
44 | - return $this->_extra_join_conditions; |
|
45 | - } |
|
46 | - /** |
|
47 | - * |
|
48 | - * @return EE_Primary_Table |
|
49 | - */ |
|
50 | - public function get_table_to_join_with() |
|
51 | - { |
|
52 | - return $this->_table_to_join_with; |
|
53 | - } |
|
54 | - /** |
|
55 | - * creates join statement FROM primary table |
|
56 | - * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | - * |
|
58 | - * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | - * @return string of SQL |
|
60 | - */ |
|
61 | - public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | - { |
|
13 | + /** |
|
14 | + * |
|
15 | + * @global type $wpdb |
|
16 | + * @param string $table_name with or without wpdb prefix |
|
17 | + * @param string $pk_column name of primary key column on THIS table |
|
18 | + * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | + * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | + * or whether each site on a multisite install has a copy of this table |
|
22 | + */ |
|
23 | + public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | + { |
|
25 | + $this->_fk_on_table = $fk_column; |
|
26 | + $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | + parent::__construct($table_name, $pk_column, $global); |
|
28 | + } |
|
29 | + public function get_fk_on_table() |
|
30 | + { |
|
31 | + return $this->_fk_on_table; |
|
32 | + } |
|
33 | + public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | + { |
|
35 | + $this->_table_to_join_with = $table; |
|
36 | + } |
|
37 | + /** |
|
38 | + * |
|
39 | + * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | + * the end of the join statement with the primary table |
|
41 | + */ |
|
42 | + public function get_extra_join_conditions() |
|
43 | + { |
|
44 | + return $this->_extra_join_conditions; |
|
45 | + } |
|
46 | + /** |
|
47 | + * |
|
48 | + * @return EE_Primary_Table |
|
49 | + */ |
|
50 | + public function get_table_to_join_with() |
|
51 | + { |
|
52 | + return $this->_table_to_join_with; |
|
53 | + } |
|
54 | + /** |
|
55 | + * creates join statement FROM primary table |
|
56 | + * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | + * |
|
58 | + * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | + * @return string of SQL |
|
60 | + */ |
|
61 | + public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | + { |
|
63 | 63 | |
64 | - $table_name = $this->get_table_name(); |
|
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | - $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | - $fk = $this->get_fk_on_table(); |
|
68 | - $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | - if ($this->get_extra_join_conditions()) { |
|
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | - } |
|
72 | - return $join_sql; |
|
73 | - } |
|
64 | + $table_name = $this->get_table_name(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | + $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | + $fk = $this->get_fk_on_table(); |
|
68 | + $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | + if ($this->get_extra_join_conditions()) { |
|
70 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | + } |
|
72 | + return $join_sql; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | - * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | - * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | - * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | - * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | - { |
|
86 | - $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | - $fk = $this->get_fk_on_table(); |
|
90 | - $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | - if ($this->get_extra_join_conditions()) { |
|
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | - } |
|
94 | - return $join_sql; |
|
95 | - } |
|
76 | + /** |
|
77 | + * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | + * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | + * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | + * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | + * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | + { |
|
86 | + $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | + $fk = $this->get_fk_on_table(); |
|
90 | + $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | + if ($this->get_extra_join_conditions()) { |
|
92 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | + } |
|
94 | + return $join_sql; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * This prepares the join on the other table using a select with a internal limit. |
|
99 | - * @param mixed (array|string) $limit limit |
|
100 | - * @return string SQL to return |
|
101 | - */ |
|
102 | - public function get_select_join_limit_join($limit) |
|
103 | - { |
|
104 | - // first get the select |
|
105 | - $select = $this->get_select_join_limit($limit); |
|
106 | - $join_sql = $this->get_join_sql($select); |
|
107 | - return $join_sql; |
|
108 | - } |
|
97 | + /** |
|
98 | + * This prepares the join on the other table using a select with a internal limit. |
|
99 | + * @param mixed (array|string) $limit limit |
|
100 | + * @return string SQL to return |
|
101 | + */ |
|
102 | + public function get_select_join_limit_join($limit) |
|
103 | + { |
|
104 | + // first get the select |
|
105 | + $select = $this->get_select_join_limit($limit); |
|
106 | + $join_sql = $this->get_join_sql($select); |
|
107 | + return $join_sql; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | 111 | |
112 | - public function get_fully_qualified_fk_column() |
|
113 | - { |
|
114 | - $table_alias = $this->get_table_alias(); |
|
115 | - $fk = $this->get_fk_on_table(); |
|
116 | - return $table_alias . '.' . $fk; |
|
117 | - } |
|
112 | + public function get_fully_qualified_fk_column() |
|
113 | + { |
|
114 | + $table_alias = $this->get_table_alias(); |
|
115 | + $fk = $this->get_fk_on_table(); |
|
116 | + return $table_alias . '.' . $fk; |
|
117 | + } |
|
118 | 118 | |
119 | - public function get_fully_qualified_pk_on_fk_table() |
|
120 | - { |
|
121 | - $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | - $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | - return $table_alias . '.' . $pk; |
|
124 | - } |
|
119 | + public function get_fully_qualified_pk_on_fk_table() |
|
120 | + { |
|
121 | + $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | + $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | + return $table_alias . '.' . $pk; |
|
124 | + } |
|
125 | 125 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | { |
63 | 63 | |
64 | 64 | $table_name = $this->get_table_name(); |
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias(); |
|
66 | 66 | $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
67 | 67 | $fk = $this->get_fk_on_table(); |
68 | 68 | $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
69 | 69 | if ($this->get_extra_join_conditions()) { |
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
70 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
71 | 71 | } |
72 | 72 | return $join_sql; |
73 | 73 | } |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
85 | 85 | { |
86 | 86 | $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column(); |
|
89 | 89 | $fk = $this->get_fk_on_table(); |
90 | 90 | $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
91 | 91 | if ($this->get_extra_join_conditions()) { |
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
92 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
93 | 93 | } |
94 | 94 | return $join_sql; |
95 | 95 | } |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | { |
114 | 114 | $table_alias = $this->get_table_alias(); |
115 | 115 | $fk = $this->get_fk_on_table(); |
116 | - return $table_alias . '.' . $fk; |
|
116 | + return $table_alias.'.'.$fk; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | public function get_fully_qualified_pk_on_fk_table() |
120 | 120 | { |
121 | 121 | $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
122 | 122 | $pk = $this->get_table_to_join_with()->get_pk_column(); |
123 | - return $table_alias . '.' . $pk; |
|
123 | + return $table_alias.'.'.$pk; |
|
124 | 124 | } |
125 | 125 | } |
@@ -1049,7 +1049,7 @@ |
||
1049 | 1049 | |
1050 | 1050 | /** |
1051 | 1051 | * @deprecated 4.9.0 |
1052 | - * @return array |
|
1052 | + * @return EE_messenger[] |
|
1053 | 1053 | */ |
1054 | 1054 | public function get_installed_messengers() |
1055 | 1055 | { |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
85 | 85 | foreach ($deprecated_filters as $deprecated_filter => $on) { |
86 | 86 | // was this filter called ? |
87 | - if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) { |
|
87 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
88 | 88 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
89 | 89 | if (EE_Registry::instance()->CAP->current_user_can( |
90 | 90 | 'ee_read_ee', |
91 | 91 | 'hide_doing_it_wrong_for_deprecated_SPCO_filter' |
92 | 92 | ) && ! defined('DOING_AJAX')) { |
93 | 93 | EE_Error::doing_it_wrong( |
94 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
94 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
95 | 95 | sprintf( |
96 | 96 | __( |
97 | 97 | '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"', |
98 | 98 | 'event_espresso' |
99 | 99 | ), |
100 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
100 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
101 | 101 | '<br />', |
102 | 102 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
103 | 103 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | } else { |
109 | - unset($deprecated_filters[ $deprecated_filter ]); |
|
109 | + unset($deprecated_filters[$deprecated_filter]); |
|
110 | 110 | } |
111 | 111 | } |
112 | - if (! empty($deprecated_filters)) { |
|
112 | + if ( ! empty($deprecated_filters)) { |
|
113 | 113 | |
114 | 114 | if ($checkout->current_step->slug( |
115 | 115 | ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $submit_button_text = apply_filters( |
144 | 144 | 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', |
145 | 145 | $submit_button_text |
146 | - ) . $checkout->next_step->name(); |
|
146 | + ).$checkout->next_step->name(); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | 'event_espresso' |
328 | 328 | ); |
329 | 329 | EE_Error::doing_it_wrong( |
330 | - __CLASS__ . '::' . __FUNCTION__, |
|
330 | + __CLASS__.'::'.__FUNCTION__, |
|
331 | 331 | $msg, |
332 | 332 | '4.8.32.rc.000' |
333 | 333 | ); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | function ee_deprecated_update_attendee_registration_form_old($admin_page) |
355 | 355 | { |
356 | 356 | // check if the old hooks are in use. If not, do the default |
357 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
357 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
358 | 358 | || ! $admin_page instanceof EE_Admin_Page) { |
359 | 359 | return; |
360 | 360 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false; |
363 | 363 | $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false; |
364 | 364 | $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
365 | - if (! $REG_ID || ! $qstns) { |
|
365 | + if ( ! $REG_ID || ! $qstns) { |
|
366 | 366 | EE_Error::add_error( |
367 | 367 | __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), |
368 | 368 | __FILE__, |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | foreach ($qstns as $QST_ID => $qstn) { |
384 | 384 | // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
385 | - if (! is_array($qstn)) { |
|
385 | + if ( ! is_array($qstn)) { |
|
386 | 386 | $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
387 | 387 | continue; |
388 | 388 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | ); |
400 | 400 | $answer = EEM_Answer::instance()->get_one($query_params); |
401 | 401 | // this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
402 | - if (! $answer instanceof EE_Answer) { |
|
402 | + if ( ! $answer instanceof EE_Answer) { |
|
403 | 403 | $set_values = array( |
404 | 404 | 'QST_ID' => $QST_ID, |
405 | 405 | 'REG_ID' => $REG_ID, |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) |
441 | 441 | { |
442 | 442 | // check if the old hooks are in use. If not, do the default |
443 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
443 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
444 | 444 | || ! $admin_page instanceof EE_Admin_Page) { |
445 | 445 | return $do_default_action; |
446 | 446 | } |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | 'reg_questions_form_action' => 'edit_registration', |
473 | 473 | 'REG_ID' => $registration->ID(), |
474 | 474 | ); |
475 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
475 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
476 | 476 | echo EEH_Template::display_template($template_path, $template_args, true); |
477 | 477 | // indicate that we should not do the default admin page code |
478 | 478 | return false; |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | public function _class_is_deprecated($method) |
591 | 591 | { |
592 | 592 | EE_Error::doing_it_wrong( |
593 | - 'EE_messages::' . $method, |
|
593 | + 'EE_messages::'.$method, |
|
594 | 594 | __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
595 | 595 | '4.9.0', |
596 | 596 | '4.10.0.p' |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | $error = false; |
730 | 730 | // try to intelligently determine what method we'll call based on the incoming data. |
731 | 731 | // if generating and sending are different then generate and send immediately. |
732 | - if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
732 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
733 | 733 | // in the legacy system, when generating and sending were different, that means all the |
734 | 734 | // vars are already in the request object. So let's just use that. |
735 | 735 | try { |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | 'event_espresso' |
743 | 743 | ); |
744 | 744 | // add specific message for developers if WP_DEBUG in on |
745 | - $error_msg .= '||' . $e->getMessage(); |
|
745 | + $error_msg .= '||'.$e->getMessage(); |
|
746 | 746 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
747 | 747 | $error = true; |
748 | 748 | } |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | } |
817 | 817 | } |
818 | 818 | // if no error then return the generated message(s). |
819 | - if (! $error && ! $send) { |
|
819 | + if ( ! $error && ! $send) { |
|
820 | 820 | $generated_queue = $processor->generate_queue(false); |
821 | 821 | // get message and return. |
822 | 822 | $generated_queue->get_message_repository()->rewind(); |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | /** @type EE_Messages_Queue $queue */ |
876 | 876 | $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
877 | 877 | // make sure we have a proper message object |
878 | - if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
878 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
879 | 879 | $msg = EE_Message_Factory::create( |
880 | 880 | array( |
881 | 881 | 'MSG_messenger' => $messenger, |
@@ -887,11 +887,11 @@ discard block |
||
887 | 887 | } else { |
888 | 888 | $msg = $message; |
889 | 889 | } |
890 | - if (! $msg instanceof EE_Message) { |
|
890 | + if ( ! $msg instanceof EE_Message) { |
|
891 | 891 | return false; |
892 | 892 | } |
893 | 893 | // make sure any content in a content property (if not empty) is set on the MSG_content. |
894 | - if (! empty($msg->content)) { |
|
894 | + if ( ! empty($msg->content)) { |
|
895 | 895 | $msg->set('MSG_content', $msg->content); |
896 | 896 | } |
897 | 897 | $queue->add($msg); |
@@ -1130,8 +1130,8 @@ discard block |
||
1130 | 1130 | |
1131 | 1131 | add_filter( |
1132 | 1132 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
1133 | - function ($event_list_iframe_css) { |
|
1134 | - if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1133 | + function($event_list_iframe_css) { |
|
1134 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1135 | 1135 | return $event_list_iframe_css; |
1136 | 1136 | } |
1137 | 1137 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1150,8 +1150,8 @@ discard block |
||
1150 | 1150 | ); |
1151 | 1151 | add_filter( |
1152 | 1152 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
1153 | - function ($event_list_iframe_js) { |
|
1154 | - if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1153 | + function($event_list_iframe_js) { |
|
1154 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1155 | 1155 | return $event_list_iframe_js; |
1156 | 1156 | } |
1157 | 1157 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1170,8 +1170,8 @@ discard block |
||
1170 | 1170 | ); |
1171 | 1171 | add_action( |
1172 | 1172 | 'AHEE__EE_Capabilities__addCaps__complete', |
1173 | - function ($capabilities_map) { |
|
1174 | - if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1173 | + function($capabilities_map) { |
|
1174 | + if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1175 | 1175 | return; |
1176 | 1176 | } |
1177 | 1177 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1190,8 +1190,8 @@ discard block |
||
1190 | 1190 | |
1191 | 1191 | add_filter( |
1192 | 1192 | 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
1193 | - function ($existing_attendee, $registration, $attendee_data) { |
|
1194 | - if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1193 | + function($existing_attendee, $registration, $attendee_data) { |
|
1194 | + if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1195 | 1195 | return $existing_attendee; |
1196 | 1196 | } |
1197 | 1197 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1274,7 +1274,7 @@ discard block |
||
1274 | 1274 | */ |
1275 | 1275 | public function event_list_title($event_list_title = '') |
1276 | 1276 | { |
1277 | - if (! empty($this->title)) { |
|
1277 | + if ( ! empty($this->title)) { |
|
1278 | 1278 | return $this->title; |
1279 | 1279 | } |
1280 | 1280 | return $event_list_title; |
@@ -1417,7 +1417,7 @@ discard block |
||
1417 | 1417 | foreach ($model_fields as $field) { |
1418 | 1418 | if ($label === EEH_Export::get_column_name_for_field($field)) { |
1419 | 1419 | // re-add the old field name |
1420 | - $new_label = $label . '[' . $field->get_name() . ']'; |
|
1420 | + $new_label = $label.'['.$field->get_name().']'; |
|
1421 | 1421 | break; |
1422 | 1422 | } |
1423 | 1423 | } |
@@ -39,31 +39,31 @@ discard block |
||
39 | 39 | * @param string $action_or_filter |
40 | 40 | */ |
41 | 41 | function deprecated_espresso_action_or_filter_doing_it_wrong( |
42 | - $deprecated_filter, |
|
43 | - $replacement, |
|
44 | - $replacement_location, |
|
45 | - $version_deprecated, |
|
46 | - $version_applies, |
|
47 | - $action_or_filter = 'action' |
|
42 | + $deprecated_filter, |
|
43 | + $replacement, |
|
44 | + $replacement_location, |
|
45 | + $version_deprecated, |
|
46 | + $version_applies, |
|
47 | + $action_or_filter = 'action' |
|
48 | 48 | ) { |
49 | - $action_or_filter = $action_or_filter === 'action' |
|
50 | - ? esc_html__('action', 'event_espresso') |
|
51 | - : esc_html__('filter', 'event_espresso'); |
|
52 | - EE_Error::doing_it_wrong( |
|
53 | - $deprecated_filter, |
|
54 | - sprintf( |
|
55 | - __( |
|
56 | - 'This %1$s is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - $action_or_filter, |
|
60 | - $replacement, |
|
61 | - $replacement_location, |
|
62 | - '<br />' |
|
63 | - ), |
|
64 | - $version_deprecated, |
|
65 | - $version_applies |
|
66 | - ); |
|
49 | + $action_or_filter = $action_or_filter === 'action' |
|
50 | + ? esc_html__('action', 'event_espresso') |
|
51 | + : esc_html__('filter', 'event_espresso'); |
|
52 | + EE_Error::doing_it_wrong( |
|
53 | + $deprecated_filter, |
|
54 | + sprintf( |
|
55 | + __( |
|
56 | + 'This %1$s is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + $action_or_filter, |
|
60 | + $replacement, |
|
61 | + $replacement_location, |
|
62 | + '<br />' |
|
63 | + ), |
|
64 | + $version_deprecated, |
|
65 | + $version_applies |
|
66 | + ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -75,90 +75,90 @@ discard block |
||
75 | 75 | */ |
76 | 76 | function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) |
77 | 77 | { |
78 | - // list of old filters |
|
79 | - $deprecated_filters = array( |
|
80 | - 'update_registration_details' => true, |
|
81 | - 'process_payment' => true, |
|
82 | - 'finalize_registration' => true, |
|
83 | - 'and_proceed_to_payment' => true, |
|
84 | - 'proceed_to' => true, |
|
85 | - ); |
|
86 | - // loop thru and call doing_it_wrong() or remove any that aren't being used |
|
87 | - foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
88 | - // was this filter called ? |
|
89 | - if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) { |
|
90 | - // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
|
91 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
92 | - 'ee_read_ee', |
|
93 | - 'hide_doing_it_wrong_for_deprecated_SPCO_filter' |
|
94 | - ) && ! defined('DOING_AJAX')) { |
|
95 | - EE_Error::doing_it_wrong( |
|
96 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
97 | - sprintf( |
|
98 | - __( |
|
99 | - '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"', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
103 | - '<br />', |
|
104 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
105 | - '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
|
106 | - ), |
|
107 | - '4.6.10' |
|
108 | - ); |
|
109 | - } |
|
110 | - } else { |
|
111 | - unset($deprecated_filters[ $deprecated_filter ]); |
|
112 | - } |
|
113 | - } |
|
114 | - if (! empty($deprecated_filters)) { |
|
115 | - |
|
116 | - if ($checkout->current_step->slug( |
|
117 | - ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
118 | - $submit_button_text = apply_filters( |
|
119 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', |
|
120 | - $submit_button_text |
|
121 | - ); |
|
122 | - } elseif ($checkout->current_step->slug( |
|
123 | - ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
124 | - $submit_button_text = apply_filters( |
|
125 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', |
|
126 | - $submit_button_text |
|
127 | - ); |
|
128 | - } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug( |
|
129 | - ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
130 | - $submit_button_text = apply_filters( |
|
131 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', |
|
132 | - $submit_button_text |
|
133 | - ); |
|
134 | - } |
|
135 | - if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
136 | - if ($checkout->payment_required() && $checkout->next_step->slug( |
|
137 | - ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
138 | - $submit_button_text .= apply_filters( |
|
139 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', |
|
140 | - $submit_button_text |
|
141 | - ); |
|
142 | - } |
|
143 | - if ($checkout->next_step->slug( |
|
144 | - ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
145 | - $submit_button_text = apply_filters( |
|
146 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', |
|
147 | - $submit_button_text |
|
148 | - ) . $checkout->next_step->name(); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - } |
|
153 | - return $submit_button_text; |
|
78 | + // list of old filters |
|
79 | + $deprecated_filters = array( |
|
80 | + 'update_registration_details' => true, |
|
81 | + 'process_payment' => true, |
|
82 | + 'finalize_registration' => true, |
|
83 | + 'and_proceed_to_payment' => true, |
|
84 | + 'proceed_to' => true, |
|
85 | + ); |
|
86 | + // loop thru and call doing_it_wrong() or remove any that aren't being used |
|
87 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
88 | + // was this filter called ? |
|
89 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) { |
|
90 | + // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
|
91 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
92 | + 'ee_read_ee', |
|
93 | + 'hide_doing_it_wrong_for_deprecated_SPCO_filter' |
|
94 | + ) && ! defined('DOING_AJAX')) { |
|
95 | + EE_Error::doing_it_wrong( |
|
96 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
97 | + sprintf( |
|
98 | + __( |
|
99 | + '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"', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
103 | + '<br />', |
|
104 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
105 | + '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
|
106 | + ), |
|
107 | + '4.6.10' |
|
108 | + ); |
|
109 | + } |
|
110 | + } else { |
|
111 | + unset($deprecated_filters[ $deprecated_filter ]); |
|
112 | + } |
|
113 | + } |
|
114 | + if (! empty($deprecated_filters)) { |
|
115 | + |
|
116 | + if ($checkout->current_step->slug( |
|
117 | + ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
118 | + $submit_button_text = apply_filters( |
|
119 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', |
|
120 | + $submit_button_text |
|
121 | + ); |
|
122 | + } elseif ($checkout->current_step->slug( |
|
123 | + ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
124 | + $submit_button_text = apply_filters( |
|
125 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', |
|
126 | + $submit_button_text |
|
127 | + ); |
|
128 | + } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug( |
|
129 | + ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
130 | + $submit_button_text = apply_filters( |
|
131 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', |
|
132 | + $submit_button_text |
|
133 | + ); |
|
134 | + } |
|
135 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
136 | + if ($checkout->payment_required() && $checkout->next_step->slug( |
|
137 | + ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
138 | + $submit_button_text .= apply_filters( |
|
139 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', |
|
140 | + $submit_button_text |
|
141 | + ); |
|
142 | + } |
|
143 | + if ($checkout->next_step->slug( |
|
144 | + ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
145 | + $submit_button_text = apply_filters( |
|
146 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', |
|
147 | + $submit_button_text |
|
148 | + ) . $checkout->next_step->name(); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + } |
|
153 | + return $submit_button_text; |
|
154 | 154 | |
155 | 155 | } |
156 | 156 | |
157 | 157 | add_filter( |
158 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
159 | - 'ee_deprecated__registration_checkout__button_text', |
|
160 | - 10, |
|
161 | - 2 |
|
158 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
159 | + 'ee_deprecated__registration_checkout__button_text', |
|
160 | + 10, |
|
161 | + 2 |
|
162 | 162 | ); |
163 | 163 | |
164 | 164 | |
@@ -170,54 +170,54 @@ discard block |
||
170 | 170 | */ |
171 | 171 | function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) |
172 | 172 | { |
173 | - $action_ref = null; |
|
174 | - $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') |
|
175 | - ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
176 | - $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') |
|
177 | - ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
178 | - if ($action_ref) { |
|
179 | - |
|
180 | - EE_Error::doing_it_wrong( |
|
181 | - $action_ref, |
|
182 | - sprintf( |
|
183 | - __( |
|
184 | - '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"', |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - '<br />', |
|
188 | - '/core/business/EE_Transaction_Processor.class.php', |
|
189 | - 'AHEE__EE_Transaction_Processor__finalize', |
|
190 | - 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
191 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
192 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing' |
|
193 | - ), |
|
194 | - '4.6.0' |
|
195 | - ); |
|
196 | - switch ($action_ref) { |
|
197 | - case 'AHEE__EE_Transaction__finalize__new_transaction' : |
|
198 | - do_action( |
|
199 | - 'AHEE__EE_Transaction__finalize__new_transaction', |
|
200 | - $checkout->transaction, |
|
201 | - $checkout->admin_request |
|
202 | - ); |
|
203 | - break; |
|
204 | - case 'AHEE__EE_Transaction__finalize__all_transaction' : |
|
205 | - do_action( |
|
206 | - 'AHEE__EE_Transaction__finalize__new_transaction', |
|
207 | - $checkout->transaction, |
|
208 | - array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), |
|
209 | - $checkout->admin_request |
|
210 | - ); |
|
211 | - break; |
|
212 | - } |
|
213 | - } |
|
173 | + $action_ref = null; |
|
174 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') |
|
175 | + ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
176 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') |
|
177 | + ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
178 | + if ($action_ref) { |
|
179 | + |
|
180 | + EE_Error::doing_it_wrong( |
|
181 | + $action_ref, |
|
182 | + sprintf( |
|
183 | + __( |
|
184 | + '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"', |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + '<br />', |
|
188 | + '/core/business/EE_Transaction_Processor.class.php', |
|
189 | + 'AHEE__EE_Transaction_Processor__finalize', |
|
190 | + 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
191 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
192 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing' |
|
193 | + ), |
|
194 | + '4.6.0' |
|
195 | + ); |
|
196 | + switch ($action_ref) { |
|
197 | + case 'AHEE__EE_Transaction__finalize__new_transaction' : |
|
198 | + do_action( |
|
199 | + 'AHEE__EE_Transaction__finalize__new_transaction', |
|
200 | + $checkout->transaction, |
|
201 | + $checkout->admin_request |
|
202 | + ); |
|
203 | + break; |
|
204 | + case 'AHEE__EE_Transaction__finalize__all_transaction' : |
|
205 | + do_action( |
|
206 | + 'AHEE__EE_Transaction__finalize__new_transaction', |
|
207 | + $checkout->transaction, |
|
208 | + array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), |
|
209 | + $checkout->admin_request |
|
210 | + ); |
|
211 | + break; |
|
212 | + } |
|
213 | + } |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | add_action( |
217 | - 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
218 | - 'ee_deprecated_finalize_transaction', |
|
219 | - 10, |
|
220 | - 2 |
|
217 | + 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
218 | + 'ee_deprecated_finalize_transaction', |
|
219 | + 10, |
|
220 | + 2 |
|
221 | 221 | ); |
222 | 222 | /** |
223 | 223 | * ee_deprecated_finalize_registration |
@@ -226,35 +226,35 @@ discard block |
||
226 | 226 | */ |
227 | 227 | function ee_deprecated_finalize_registration(EE_Registration $registration) |
228 | 228 | { |
229 | - $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') |
|
230 | - ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null; |
|
231 | - if ($action_ref) { |
|
232 | - EE_Error::doing_it_wrong( |
|
233 | - $action_ref, |
|
234 | - sprintf( |
|
235 | - __( |
|
236 | - '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"', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - '<br />', |
|
240 | - '/core/business/EE_Registration_Processor.class.php', |
|
241 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications' |
|
242 | - ), |
|
243 | - '4.6.0' |
|
244 | - ); |
|
245 | - do_action( |
|
246 | - 'AHEE__EE_Registration__finalize__update_and_new_reg', |
|
247 | - $registration, |
|
248 | - (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) |
|
249 | - ); |
|
250 | - } |
|
229 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') |
|
230 | + ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null; |
|
231 | + if ($action_ref) { |
|
232 | + EE_Error::doing_it_wrong( |
|
233 | + $action_ref, |
|
234 | + sprintf( |
|
235 | + __( |
|
236 | + '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"', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + '<br />', |
|
240 | + '/core/business/EE_Registration_Processor.class.php', |
|
241 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications' |
|
242 | + ), |
|
243 | + '4.6.0' |
|
244 | + ); |
|
245 | + do_action( |
|
246 | + 'AHEE__EE_Registration__finalize__update_and_new_reg', |
|
247 | + $registration, |
|
248 | + (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) |
|
249 | + ); |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | add_action( |
254 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
255 | - 'ee_deprecated_finalize_registration', |
|
256 | - 10, |
|
257 | - 1 |
|
254 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
255 | + 'ee_deprecated_finalize_registration', |
|
256 | + 10, |
|
257 | + 1 |
|
258 | 258 | ); |
259 | 259 | |
260 | 260 | |
@@ -264,44 +264,44 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function ee_deprecated_hooks() |
266 | 266 | { |
267 | - /** |
|
268 | - * @var $hooks array where keys are hook names, and their values are array{ |
|
269 | - * @type string $version when deprecated |
|
270 | - * @type string $alternative saying what to use instead |
|
271 | - * @type boolean $still_works whether or not the hook still works |
|
272 | - * } |
|
273 | - */ |
|
274 | - $hooks = array( |
|
275 | - 'AHEE__EE_System___do_setup_validations' => array( |
|
276 | - 'version' => '4.6.0', |
|
277 | - 'alternative' => __( |
|
278 | - 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - 'still_works' => false, |
|
282 | - ), |
|
283 | - ); |
|
284 | - foreach ($hooks as $name => $deprecation_info) { |
|
285 | - if (has_action($name)) { |
|
286 | - EE_Error::doing_it_wrong( |
|
287 | - $name, |
|
288 | - sprintf( |
|
289 | - __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
290 | - $deprecation_info['still_works'] ? __( |
|
291 | - 'It *may* work as an attempt to build in backwards compatibility.', |
|
292 | - 'event_espresso' |
|
293 | - ) : __('It has been completely removed.', 'event_espresso'), |
|
294 | - isset($deprecation_info['alternative']) |
|
295 | - ? $deprecation_info['alternative'] |
|
296 | - : __( |
|
297 | - 'Please read the current EE4 documentation further or contact Support.', |
|
298 | - 'event_espresso' |
|
299 | - ) |
|
300 | - ), |
|
301 | - isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
302 | - ); |
|
303 | - } |
|
304 | - } |
|
267 | + /** |
|
268 | + * @var $hooks array where keys are hook names, and their values are array{ |
|
269 | + * @type string $version when deprecated |
|
270 | + * @type string $alternative saying what to use instead |
|
271 | + * @type boolean $still_works whether or not the hook still works |
|
272 | + * } |
|
273 | + */ |
|
274 | + $hooks = array( |
|
275 | + 'AHEE__EE_System___do_setup_validations' => array( |
|
276 | + 'version' => '4.6.0', |
|
277 | + 'alternative' => __( |
|
278 | + 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + 'still_works' => false, |
|
282 | + ), |
|
283 | + ); |
|
284 | + foreach ($hooks as $name => $deprecation_info) { |
|
285 | + if (has_action($name)) { |
|
286 | + EE_Error::doing_it_wrong( |
|
287 | + $name, |
|
288 | + sprintf( |
|
289 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
290 | + $deprecation_info['still_works'] ? __( |
|
291 | + 'It *may* work as an attempt to build in backwards compatibility.', |
|
292 | + 'event_espresso' |
|
293 | + ) : __('It has been completely removed.', 'event_espresso'), |
|
294 | + isset($deprecation_info['alternative']) |
|
295 | + ? $deprecation_info['alternative'] |
|
296 | + : __( |
|
297 | + 'Please read the current EE4 documentation further or contact Support.', |
|
298 | + 'event_espresso' |
|
299 | + ) |
|
300 | + ), |
|
301 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
302 | + ); |
|
303 | + } |
|
304 | + } |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
@@ -316,34 +316,34 @@ discard block |
||
316 | 316 | */ |
317 | 317 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
318 | 318 | { |
319 | - $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
320 | - || has_action( |
|
321 | - 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' |
|
322 | - ); |
|
323 | - if ($in_use) { |
|
324 | - $msg = __( |
|
325 | - '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.' |
|
326 | - . '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,' |
|
327 | - . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end ' |
|
328 | - . 'to add other actions after a form submission has been received.', |
|
329 | - 'event_espresso' |
|
330 | - ); |
|
331 | - EE_Error::doing_it_wrong( |
|
332 | - __CLASS__ . '::' . __FUNCTION__, |
|
333 | - $msg, |
|
334 | - '4.8.32.rc.000' |
|
335 | - ); |
|
336 | - // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
|
337 | - if (is_admin() && ! defined('DOING_AJAX')) { |
|
338 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
339 | - } |
|
340 | - } |
|
341 | - return $in_use; |
|
319 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
320 | + || has_action( |
|
321 | + 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' |
|
322 | + ); |
|
323 | + if ($in_use) { |
|
324 | + $msg = __( |
|
325 | + '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.' |
|
326 | + . '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,' |
|
327 | + . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end ' |
|
328 | + . 'to add other actions after a form submission has been received.', |
|
329 | + 'event_espresso' |
|
330 | + ); |
|
331 | + EE_Error::doing_it_wrong( |
|
332 | + __CLASS__ . '::' . __FUNCTION__, |
|
333 | + $msg, |
|
334 | + '4.8.32.rc.000' |
|
335 | + ); |
|
336 | + // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
|
337 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
338 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
339 | + } |
|
340 | + } |
|
341 | + return $in_use; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | add_action( |
345 | - 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', |
|
346 | - 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' |
|
345 | + 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', |
|
346 | + 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | /** |
@@ -355,77 +355,77 @@ discard block |
||
355 | 355 | */ |
356 | 356 | function ee_deprecated_update_attendee_registration_form_old($admin_page) |
357 | 357 | { |
358 | - // check if the old hooks are in use. If not, do the default |
|
359 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
360 | - || ! $admin_page instanceof EE_Admin_Page) { |
|
361 | - return; |
|
362 | - } |
|
363 | - $req_data = $admin_page->get_request_data(); |
|
364 | - $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false; |
|
365 | - $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false; |
|
366 | - $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
367 | - if (! $REG_ID || ! $qstns) { |
|
368 | - EE_Error::add_error( |
|
369 | - __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), |
|
370 | - __FILE__, |
|
371 | - __FUNCTION__, |
|
372 | - __LINE__ |
|
373 | - ); |
|
374 | - } |
|
375 | - $success = true; |
|
376 | - |
|
377 | - // allow others to get in on this awesome fun :D |
|
378 | - do_action( |
|
379 | - 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', |
|
380 | - $REG_ID, |
|
381 | - $qstns |
|
382 | - ); |
|
383 | - // loop thru questions... FINALLY!!! |
|
384 | - |
|
385 | - foreach ($qstns as $QST_ID => $qstn) { |
|
386 | - // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
|
387 | - if (! is_array($qstn)) { |
|
388 | - $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
389 | - continue; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - foreach ($qstn as $ANS_ID => $ANS_value) { |
|
394 | - // get answer |
|
395 | - $query_params = array( |
|
396 | - 0 => array( |
|
397 | - 'ANS_ID' => $ANS_ID, |
|
398 | - 'REG_ID' => $REG_ID, |
|
399 | - 'QST_ID' => $QST_ID, |
|
400 | - ), |
|
401 | - ); |
|
402 | - $answer = EEM_Answer::instance()->get_one($query_params); |
|
403 | - // this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
|
404 | - if (! $answer instanceof EE_Answer) { |
|
405 | - $set_values = array( |
|
406 | - 'QST_ID' => $QST_ID, |
|
407 | - 'REG_ID' => $REG_ID, |
|
408 | - 'ANS_value' => $qstn, |
|
409 | - ); |
|
410 | - $success = EEM_Answer::instance()->insert($set_values); |
|
411 | - continue 2; |
|
412 | - } |
|
413 | - |
|
414 | - $answer->set('ANS_value', $ANS_value); |
|
415 | - $success = $answer->save(); |
|
416 | - } |
|
417 | - } |
|
418 | - $what = __('Registration Form', 'event_espresso'); |
|
419 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
420 | - $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
421 | - exit; |
|
358 | + // check if the old hooks are in use. If not, do the default |
|
359 | + if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
360 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
361 | + return; |
|
362 | + } |
|
363 | + $req_data = $admin_page->get_request_data(); |
|
364 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false; |
|
365 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false; |
|
366 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
367 | + if (! $REG_ID || ! $qstns) { |
|
368 | + EE_Error::add_error( |
|
369 | + __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), |
|
370 | + __FILE__, |
|
371 | + __FUNCTION__, |
|
372 | + __LINE__ |
|
373 | + ); |
|
374 | + } |
|
375 | + $success = true; |
|
376 | + |
|
377 | + // allow others to get in on this awesome fun :D |
|
378 | + do_action( |
|
379 | + 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', |
|
380 | + $REG_ID, |
|
381 | + $qstns |
|
382 | + ); |
|
383 | + // loop thru questions... FINALLY!!! |
|
384 | + |
|
385 | + foreach ($qstns as $QST_ID => $qstn) { |
|
386 | + // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
|
387 | + if (! is_array($qstn)) { |
|
388 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
389 | + continue; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
394 | + // get answer |
|
395 | + $query_params = array( |
|
396 | + 0 => array( |
|
397 | + 'ANS_ID' => $ANS_ID, |
|
398 | + 'REG_ID' => $REG_ID, |
|
399 | + 'QST_ID' => $QST_ID, |
|
400 | + ), |
|
401 | + ); |
|
402 | + $answer = EEM_Answer::instance()->get_one($query_params); |
|
403 | + // this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
|
404 | + if (! $answer instanceof EE_Answer) { |
|
405 | + $set_values = array( |
|
406 | + 'QST_ID' => $QST_ID, |
|
407 | + 'REG_ID' => $REG_ID, |
|
408 | + 'ANS_value' => $qstn, |
|
409 | + ); |
|
410 | + $success = EEM_Answer::instance()->insert($set_values); |
|
411 | + continue 2; |
|
412 | + } |
|
413 | + |
|
414 | + $answer->set('ANS_value', $ANS_value); |
|
415 | + $success = $answer->save(); |
|
416 | + } |
|
417 | + } |
|
418 | + $what = __('Registration Form', 'event_espresso'); |
|
419 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
420 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
421 | + exit; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | add_action( |
425 | - 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', |
|
426 | - 'ee_deprecated_update_attendee_registration_form_old', |
|
427 | - 10, |
|
428 | - 1 |
|
425 | + 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', |
|
426 | + 'ee_deprecated_update_attendee_registration_form_old', |
|
427 | + 10, |
|
428 | + 1 |
|
429 | 429 | ); |
430 | 430 | /** |
431 | 431 | * Render the registration admin page's custom questions area in the old fashion |
@@ -441,50 +441,50 @@ discard block |
||
441 | 441 | */ |
442 | 442 | function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) |
443 | 443 | { |
444 | - // check if the old hooks are in use. If not, do the default |
|
445 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
446 | - || ! $admin_page instanceof EE_Admin_Page) { |
|
447 | - return $do_default_action; |
|
448 | - } |
|
449 | - add_filter( |
|
450 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
451 | - array($admin_page, 'form_before_question_group'), |
|
452 | - 10, |
|
453 | - 1 |
|
454 | - ); |
|
455 | - add_filter( |
|
456 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
457 | - array($admin_page, 'form_after_question_group'), |
|
458 | - 10, |
|
459 | - 1 |
|
460 | - ); |
|
461 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
462 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
463 | - |
|
464 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( |
|
465 | - $registration, |
|
466 | - $registration->get( |
|
467 | - 'EVT_ID' |
|
468 | - ) |
|
469 | - ); |
|
470 | - |
|
471 | - EE_Registry::instance()->load_helper('Form_Fields'); |
|
472 | - $template_args = array( |
|
473 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
474 | - 'reg_questions_form_action' => 'edit_registration', |
|
475 | - 'REG_ID' => $registration->ID(), |
|
476 | - ); |
|
477 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
478 | - echo EEH_Template::display_template($template_path, $template_args, true); |
|
479 | - // indicate that we should not do the default admin page code |
|
480 | - return false; |
|
444 | + // check if the old hooks are in use. If not, do the default |
|
445 | + if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
446 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
447 | + return $do_default_action; |
|
448 | + } |
|
449 | + add_filter( |
|
450 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
451 | + array($admin_page, 'form_before_question_group'), |
|
452 | + 10, |
|
453 | + 1 |
|
454 | + ); |
|
455 | + add_filter( |
|
456 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
457 | + array($admin_page, 'form_after_question_group'), |
|
458 | + 10, |
|
459 | + 1 |
|
460 | + ); |
|
461 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
462 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
463 | + |
|
464 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( |
|
465 | + $registration, |
|
466 | + $registration->get( |
|
467 | + 'EVT_ID' |
|
468 | + ) |
|
469 | + ); |
|
470 | + |
|
471 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
472 | + $template_args = array( |
|
473 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
474 | + 'reg_questions_form_action' => 'edit_registration', |
|
475 | + 'REG_ID' => $registration->ID(), |
|
476 | + ); |
|
477 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
478 | + echo EEH_Template::display_template($template_path, $template_args, true); |
|
479 | + // indicate that we should not do the default admin page code |
|
480 | + return false; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | add_action( |
484 | - 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
485 | - 'ee_deprecated_reg_questions_meta_box_old', |
|
486 | - 10, |
|
487 | - 3 |
|
484 | + 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
485 | + 'ee_deprecated_reg_questions_meta_box_old', |
|
486 | + 10, |
|
487 | + 3 |
|
488 | 488 | ); |
489 | 489 | |
490 | 490 | |
@@ -501,42 +501,42 @@ discard block |
||
501 | 501 | class EE_Message_Template_Defaults extends EE_Base |
502 | 502 | { |
503 | 503 | |
504 | - /** |
|
505 | - * EE_Message_Template_Defaults constructor. |
|
506 | - * |
|
507 | - * @param EE_messages $messages |
|
508 | - * @param $messenger_name |
|
509 | - * @param $message_type_name |
|
510 | - * @param int $GRP_ID |
|
511 | - * @return EE_Messages_Template_Defaults |
|
512 | - */ |
|
513 | - public function __construct( |
|
514 | - EE_messages $messages, |
|
515 | - $messenger_name, |
|
516 | - $message_type_name, |
|
517 | - $GRP_ID = 0 |
|
518 | - ) { |
|
519 | - EE_Error::doing_it_wrong( |
|
520 | - __FUNCTION__, |
|
521 | - __( |
|
522 | - 'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.', |
|
523 | - 'event_espresso' |
|
524 | - ), |
|
525 | - '4.9.0' |
|
526 | - ); |
|
527 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
528 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
529 | - $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
530 | - $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
531 | - return EE_Registry::instance()->load_lib( |
|
532 | - 'Messages_Template_Defaults', |
|
533 | - array( |
|
534 | - $GRP_ID, |
|
535 | - $messenger, |
|
536 | - $message_type, |
|
537 | - ) |
|
538 | - ); |
|
539 | - } |
|
504 | + /** |
|
505 | + * EE_Message_Template_Defaults constructor. |
|
506 | + * |
|
507 | + * @param EE_messages $messages |
|
508 | + * @param $messenger_name |
|
509 | + * @param $message_type_name |
|
510 | + * @param int $GRP_ID |
|
511 | + * @return EE_Messages_Template_Defaults |
|
512 | + */ |
|
513 | + public function __construct( |
|
514 | + EE_messages $messages, |
|
515 | + $messenger_name, |
|
516 | + $message_type_name, |
|
517 | + $GRP_ID = 0 |
|
518 | + ) { |
|
519 | + EE_Error::doing_it_wrong( |
|
520 | + __FUNCTION__, |
|
521 | + __( |
|
522 | + 'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.', |
|
523 | + 'event_espresso' |
|
524 | + ), |
|
525 | + '4.9.0' |
|
526 | + ); |
|
527 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
528 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
529 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
530 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
531 | + return EE_Registry::instance()->load_lib( |
|
532 | + 'Messages_Template_Defaults', |
|
533 | + array( |
|
534 | + $GRP_ID, |
|
535 | + $messenger, |
|
536 | + $message_type, |
|
537 | + ) |
|
538 | + ); |
|
539 | + } |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | |
@@ -554,525 +554,525 @@ discard block |
||
554 | 554 | class EE_messages |
555 | 555 | { |
556 | 556 | |
557 | - /** @type EE_messenger[] */ |
|
558 | - protected $_active_messengers = array(); |
|
559 | - |
|
560 | - /** @type array */ |
|
561 | - protected $_active_message_types = array(); |
|
562 | - |
|
563 | - /** @type EE_message_type[] */ |
|
564 | - protected $_installed_message_types = array(); |
|
565 | - |
|
566 | - /** @type EE_messenger */ |
|
567 | - protected $_messenger; |
|
568 | - |
|
569 | - /** @type EE_message_type */ |
|
570 | - protected $_message_type; |
|
571 | - |
|
572 | - /** @type array */ |
|
573 | - protected $_contexts = array(); |
|
574 | - |
|
575 | - /** @type EE_Message_Resource_Manager $_message_resource_manager */ |
|
576 | - protected $_message_resource_manager; |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * EE_messages constructor. |
|
581 | - * |
|
582 | - * @deprecated 4.9.0 |
|
583 | - */ |
|
584 | - public function __construct() |
|
585 | - { |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * @param string $method |
|
591 | - */ |
|
592 | - public function _class_is_deprecated($method) |
|
593 | - { |
|
594 | - EE_Error::doing_it_wrong( |
|
595 | - 'EE_messages::' . $method, |
|
596 | - __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
597 | - '4.9.0', |
|
598 | - '4.10.0.p' |
|
599 | - ); |
|
600 | - // Please use EE_Message_Resource_Manager instead |
|
601 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * @deprecated 4.9.0 |
|
607 | - * @param string $messenger_name |
|
608 | - * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
|
609 | - */ |
|
610 | - public function ensure_messenger_is_active($messenger_name) |
|
611 | - { |
|
612 | - // EE_messages has been deprecated |
|
613 | - $this->_class_is_deprecated(__FUNCTION__); |
|
614 | - return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * @deprecated 4.9.0 |
|
620 | - * @param string $message_type message type name |
|
621 | - * @param $messenger |
|
622 | - * @return bool true if it got activated (or was active) and false if not. |
|
623 | - * @throws \EE_Error |
|
624 | - */ |
|
625 | - public function ensure_message_type_is_active($message_type, $messenger) |
|
626 | - { |
|
627 | - // EE_messages has been deprecated |
|
628 | - $this->_class_is_deprecated(__FUNCTION__); |
|
629 | - return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * @deprecated 4.9.0 |
|
635 | - * @param string $messenger_name |
|
636 | - * @param array $mts_to_activate (optional) An array of message types to activate with this messenger. |
|
637 | - * If included we do NOT setup the default message types (assuming they |
|
638 | - * are already setup.) |
|
639 | - * @return boolean an array of generated templates or false if nothing generated/activated. |
|
640 | - */ |
|
641 | - public function activate_messenger($messenger_name, $mts_to_activate = array()) |
|
642 | - { |
|
643 | - // EE_messages has been deprecated |
|
644 | - $this->_class_is_deprecated(__FUNCTION__); |
|
645 | - return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @deprecated 4.9.0 |
|
651 | - * @param EE_messenger $messenger messenger used in trigger |
|
652 | - * @param EE_message_type $message_type message type used in trigger |
|
653 | - * |
|
654 | - * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
655 | - */ |
|
656 | - public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
657 | - { |
|
658 | - // EE_messages has been deprecated |
|
659 | - $this->_class_is_deprecated(__FUNCTION__); |
|
660 | - return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * @deprecated 4.9.0 |
|
666 | - * @param string $messenger |
|
667 | - * @return EE_messenger | null |
|
668 | - */ |
|
669 | - public function get_messenger_if_active($messenger) |
|
670 | - { |
|
671 | - // EE_messages has been deprecated |
|
672 | - $this->_class_is_deprecated(__FUNCTION__); |
|
673 | - return $this->_message_resource_manager->get_active_messenger($messenger); |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * @deprecated 4.9.0 |
|
679 | - * @param EE_Message $message |
|
680 | - * @return array An array with 'messenger' and 'message_type' as the index and the corresponding valid object if |
|
681 | - * available. |
|
682 | - * Eg. Valid Messenger and Message Type: |
|
683 | - * array( |
|
684 | - * 'messenger' => new EE_Email_messenger(), |
|
685 | - * 'message_type' => new EE_Registration_Approved_message_type() |
|
686 | - * ) |
|
687 | - * Valid Messenger and Invalid Message Type: |
|
688 | - * array( |
|
689 | - * 'messenger' => new EE_Email_messenger(), |
|
690 | - * 'message_type' => null |
|
691 | - * ) |
|
692 | - */ |
|
693 | - public function validate_for_use(EE_Message $message) |
|
694 | - { |
|
695 | - // EE_messages has been deprecated |
|
696 | - $this->_class_is_deprecated(__FUNCTION__); |
|
697 | - return array( |
|
698 | - 'messenger' => $message->messenger_object(), |
|
699 | - 'message_type' => $message->message_type_object(), |
|
700 | - ); |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @deprecated 4.9.0 |
|
706 | - * @param string $type What type of message are we sending (corresponds to message types) |
|
707 | - * @param mixed $vars Data being sent for parsing in the message |
|
708 | - * @param string $sending_messenger if included then we ONLY use the specified messenger for delivery. |
|
709 | - * Otherwise we cycle through all active messengers. |
|
710 | - * @param string $generating_messenger if included then this messenger is used for generating the message |
|
711 | - * templates (but not for sending). |
|
712 | - * @param string $context If included then only a message type for a specific context will be |
|
713 | - * generated. |
|
714 | - * @param bool $send Default TRUE. If false, then this will just return the generated |
|
715 | - * EE_messages objects which might be used by the trigger to setup a batch |
|
716 | - * message (typically html messenger uses it). |
|
717 | - * @return bool |
|
718 | - */ |
|
719 | - public function send_message( |
|
720 | - $type, |
|
721 | - $vars, |
|
722 | - $sending_messenger = '', |
|
723 | - $generating_messenger = '', |
|
724 | - $context = '', |
|
725 | - $send = true |
|
726 | - ) { |
|
727 | - // EE_messages has been deprecated |
|
728 | - $this->_class_is_deprecated(__FUNCTION__); |
|
729 | - /** @type EE_Messages_Processor $processor */ |
|
730 | - $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
731 | - $error = false; |
|
732 | - // try to intelligently determine what method we'll call based on the incoming data. |
|
733 | - // if generating and sending are different then generate and send immediately. |
|
734 | - if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
735 | - // in the legacy system, when generating and sending were different, that means all the |
|
736 | - // vars are already in the request object. So let's just use that. |
|
737 | - try { |
|
738 | - /** @type EE_Message_To_Generate_From_Request $mtg */ |
|
739 | - $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
740 | - $processor->generate_and_send_now($mtg); |
|
741 | - } catch (EE_Error $e) { |
|
742 | - $error_msg = __( |
|
743 | - 'Please note that a system message failed to send due to a technical issue.', |
|
744 | - 'event_espresso' |
|
745 | - ); |
|
746 | - // add specific message for developers if WP_DEBUG in on |
|
747 | - $error_msg .= '||' . $e->getMessage(); |
|
748 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
749 | - $error = true; |
|
750 | - } |
|
751 | - } else { |
|
752 | - $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
753 | - // let's find out if there were any errors and how many successfully were queued. |
|
754 | - $count_errors = $processor->get_queue()->count_STS_in_queue( |
|
755 | - array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
756 | - ); |
|
757 | - $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
758 | - $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
759 | - $count_errors = $count_errors + $count_retry; |
|
760 | - if ($count_errors > 0) { |
|
761 | - $error = true; |
|
762 | - if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
763 | - $message = sprintf( |
|
764 | - __( |
|
765 | - 'There were %d errors and %d messages successfully queued for generation and sending', |
|
766 | - 'event_espresso' |
|
767 | - ), |
|
768 | - $count_errors, |
|
769 | - $count_queued |
|
770 | - ); |
|
771 | - } elseif ($count_errors > 1 && $count_queued === 1) { |
|
772 | - $message = sprintf( |
|
773 | - __( |
|
774 | - 'There were %d errors and %d message successfully queued for generation.', |
|
775 | - 'event_espresso' |
|
776 | - ), |
|
777 | - $count_errors, |
|
778 | - $count_queued |
|
779 | - ); |
|
780 | - } elseif ($count_errors === 1 && $count_queued > 1) { |
|
781 | - $message = sprintf( |
|
782 | - __( |
|
783 | - 'There was %d error and %d messages successfully queued for generation.', |
|
784 | - 'event_espresso' |
|
785 | - ), |
|
786 | - $count_errors, |
|
787 | - $count_queued |
|
788 | - ); |
|
789 | - } else { |
|
790 | - $message = sprintf( |
|
791 | - __( |
|
792 | - 'There was %d message that failed to be queued for generation.', |
|
793 | - 'event_espresso' |
|
794 | - ), |
|
795 | - $count_errors |
|
796 | - ); |
|
797 | - } |
|
798 | - EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
799 | - } else { |
|
800 | - if ($count_queued === 1) { |
|
801 | - $message = sprintf( |
|
802 | - __( |
|
803 | - '%d message successfully queued for generation.', |
|
804 | - 'event_espresso' |
|
805 | - ), |
|
806 | - $count_queued |
|
807 | - ); |
|
808 | - } else { |
|
809 | - $message = sprintf( |
|
810 | - __( |
|
811 | - '%d messages were successfully queued for generation.', |
|
812 | - 'event_espresso' |
|
813 | - ), |
|
814 | - $count_queued |
|
815 | - ); |
|
816 | - } |
|
817 | - EE_Error::add_success($message); |
|
818 | - } |
|
819 | - } |
|
820 | - // if no error then return the generated message(s). |
|
821 | - if (! $error && ! $send) { |
|
822 | - $generated_queue = $processor->generate_queue(false); |
|
823 | - // get message and return. |
|
824 | - $generated_queue->get_message_repository()->rewind(); |
|
825 | - $messages = array(); |
|
826 | - while ($generated_queue->get_message_repository()->valid()) { |
|
827 | - $message = $generated_queue->get_message_repository()->current(); |
|
828 | - if ($message instanceof EE_Message) { |
|
829 | - // set properties that might be expected by add-ons (backward compat) |
|
830 | - $message->content = $message->content(); |
|
831 | - $message->template_pack = $message->get_template_pack(); |
|
832 | - $message->template_variation = $message->get_template_pack_variation(); |
|
833 | - $messages[] = $message; |
|
834 | - } |
|
835 | - $generated_queue->get_message_repository()->next(); |
|
836 | - } |
|
837 | - return $messages; |
|
838 | - } |
|
839 | - return $error ? false |
|
840 | - : true; // yeah backwards eh? Really what we're returning is if there is a total success for all the messages or not. We'll modify this once we get message recording in place. |
|
841 | - } |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * @deprecated 4.9.0 |
|
846 | - * @param string $type This should correspond with a valid message type |
|
847 | - * @param string $context This should correspond with a valid context for the message type |
|
848 | - * @param string $messenger This should correspond with a valid messenger. |
|
849 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
850 | - * preview |
|
851 | - * @return string The body of the message. |
|
852 | - */ |
|
853 | - public function preview_message($type, $context, $messenger, $send = false) |
|
854 | - { |
|
855 | - // EE_messages has been deprecated |
|
856 | - $this->_class_is_deprecated(__FUNCTION__); |
|
857 | - return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * @since 4.5.0 |
|
863 | - * @deprecated 4.9.0 Moved to EED_Messages Module |
|
864 | - * @param string $messenger a string matching a valid active messenger in the system |
|
865 | - * @param string $message_type Although it seems contrary to the name of the method, a message type name is still |
|
866 | - * required to send along the message type to the messenger because this is used for |
|
867 | - * determining what specific variations might be loaded for the generated message. |
|
868 | - * @param stdClass $message a stdClass object in the format expected by the messenger. |
|
869 | - * |
|
870 | - * @return bool success or fail. |
|
871 | - */ |
|
872 | - public function send_message_with_messenger_only($messenger, $message_type, $message) |
|
873 | - { |
|
874 | - // EE_messages has been deprecated |
|
875 | - $this->_class_is_deprecated(__FUNCTION__); |
|
876 | - // setup for sending to new method. |
|
877 | - /** @type EE_Messages_Queue $queue */ |
|
878 | - $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
879 | - // make sure we have a proper message object |
|
880 | - if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
881 | - $msg = EE_Message_Factory::create( |
|
882 | - array( |
|
883 | - 'MSG_messenger' => $messenger, |
|
884 | - 'MSG_message_type' => $message_type, |
|
885 | - 'MSG_content' => $message->content, |
|
886 | - 'MSG_subject' => $message->subject, |
|
887 | - ) |
|
888 | - ); |
|
889 | - } else { |
|
890 | - $msg = $message; |
|
891 | - } |
|
892 | - if (! $msg instanceof EE_Message) { |
|
893 | - return false; |
|
894 | - } |
|
895 | - // make sure any content in a content property (if not empty) is set on the MSG_content. |
|
896 | - if (! empty($msg->content)) { |
|
897 | - $msg->set('MSG_content', $msg->content); |
|
898 | - } |
|
899 | - $queue->add($msg); |
|
900 | - return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * @deprecated 4.9.0 |
|
906 | - * @param $messenger |
|
907 | - * @param string $message_type message type that the templates are being created for |
|
908 | - * @param int $GRP_ID |
|
909 | - * @param bool $is_global |
|
910 | - * @return array|object if creation is successful then we return an array of info, otherwise an error_object is |
|
911 | - * returned. |
|
912 | - * @throws \EE_Error |
|
913 | - */ |
|
914 | - public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) |
|
915 | - { |
|
916 | - // EE_messages has been deprecated |
|
917 | - $this->_class_is_deprecated(__FUNCTION__); |
|
918 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
919 | - return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * @deprecated 4.9.0 |
|
925 | - * @param string $messenger_name name of EE_messenger |
|
926 | - * @param string $message_type_name name of EE_message_type |
|
927 | - * @return array |
|
928 | - */ |
|
929 | - public function get_fields($messenger_name, $message_type_name) |
|
930 | - { |
|
931 | - // EE_messages has been deprecated |
|
932 | - $this->_class_is_deprecated(__FUNCTION__); |
|
933 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
934 | - return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * @deprecated 4.9.0 |
|
940 | - * @access public |
|
941 | - * @param string $type we can indicate just returning installed message types |
|
942 | - * or messengers (or both) via this parameter. |
|
943 | - * @param bool $skip_cache if true then we skip the cache and retrieve via files. |
|
944 | - * @return array multidimensional array of messenger and message_type objects |
|
945 | - * (messengers index, and message_type index); |
|
946 | - */ |
|
947 | - public function get_installed($type = 'all', $skip_cache = false) |
|
948 | - { |
|
949 | - // EE_messages has been deprecated |
|
950 | - $this->_class_is_deprecated(__FUNCTION__); |
|
951 | - if ($skip_cache) { |
|
952 | - $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
|
953 | - } |
|
954 | - switch ($type) { |
|
955 | - case 'messengers' : |
|
956 | - return array( |
|
957 | - 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
958 | - ); |
|
959 | - break; |
|
960 | - case 'message_types' : |
|
961 | - return array( |
|
962 | - 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
963 | - ); |
|
964 | - break; |
|
965 | - case 'all' : |
|
966 | - default : |
|
967 | - return array( |
|
968 | - 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
969 | - 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
970 | - ); |
|
971 | - break; |
|
972 | - } |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * @deprecated 4.9.0 |
|
978 | - * @return \EE_messenger[] |
|
979 | - */ |
|
980 | - public function get_active_messengers() |
|
981 | - { |
|
982 | - // EE_messages has been deprecated |
|
983 | - $this->_class_is_deprecated(__FUNCTION__); |
|
984 | - return $this->_message_resource_manager->active_messengers(); |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * @deprecated 4.9.0 |
|
990 | - * @return array array of message_type references (string) |
|
991 | - */ |
|
992 | - public function get_active_message_types() |
|
993 | - { |
|
994 | - // EE_messages has been deprecated |
|
995 | - $this->_class_is_deprecated(__FUNCTION__); |
|
996 | - return $this->_message_resource_manager->list_of_active_message_types(); |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - /** |
|
1001 | - * @deprecated 4.9.0 |
|
1002 | - * @return EE_message_type[] |
|
1003 | - */ |
|
1004 | - public function get_active_message_type_objects() |
|
1005 | - { |
|
1006 | - // EE_messages has been deprecated |
|
1007 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1008 | - return $this->_message_resource_manager->get_active_message_type_objects(); |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * @deprecated 4.9.0 |
|
1014 | - * @since 4.5.0 |
|
1015 | - * @param string $messenger The messenger being checked |
|
1016 | - * @return EE_message_type[] (or empty array if none present) |
|
1017 | - */ |
|
1018 | - public function get_active_message_types_per_messenger($messenger) |
|
1019 | - { |
|
1020 | - // EE_messages has been deprecated |
|
1021 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1022 | - return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * @deprecated 4.9.0 |
|
1028 | - * @param string $messenger The string should correspond to the messenger (message types are |
|
1029 | - * @param string $message_type The string should correspond to a message type. |
|
1030 | - * @return EE_message_type|null |
|
1031 | - */ |
|
1032 | - public function get_active_message_type($messenger, $message_type) |
|
1033 | - { |
|
1034 | - // EE_messages has been deprecated |
|
1035 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1036 | - return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
1037 | - } |
|
1038 | - |
|
1039 | - |
|
1040 | - /** |
|
1041 | - * @deprecated 4.9.0 |
|
1042 | - * @return array|\EE_message_type[] |
|
1043 | - */ |
|
1044 | - public function get_installed_message_types() |
|
1045 | - { |
|
1046 | - // EE_messages has been deprecated |
|
1047 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1048 | - return $this->_message_resource_manager->installed_message_types(); |
|
1049 | - } |
|
1050 | - |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * @deprecated 4.9.0 |
|
1054 | - * @return array |
|
1055 | - */ |
|
1056 | - public function get_installed_messengers() |
|
1057 | - { |
|
1058 | - // EE_messages has been deprecated |
|
1059 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1060 | - return $this->_message_resource_manager->installed_messengers(); |
|
1061 | - } |
|
1062 | - |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * @deprecated 4.9.0 |
|
1066 | - * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by |
|
1067 | - * message type. |
|
1068 | - * @return array |
|
1069 | - */ |
|
1070 | - public function get_all_contexts($slugs_only = true) |
|
1071 | - { |
|
1072 | - // EE_messages has been deprecated |
|
1073 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1074 | - return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
1075 | - } |
|
557 | + /** @type EE_messenger[] */ |
|
558 | + protected $_active_messengers = array(); |
|
559 | + |
|
560 | + /** @type array */ |
|
561 | + protected $_active_message_types = array(); |
|
562 | + |
|
563 | + /** @type EE_message_type[] */ |
|
564 | + protected $_installed_message_types = array(); |
|
565 | + |
|
566 | + /** @type EE_messenger */ |
|
567 | + protected $_messenger; |
|
568 | + |
|
569 | + /** @type EE_message_type */ |
|
570 | + protected $_message_type; |
|
571 | + |
|
572 | + /** @type array */ |
|
573 | + protected $_contexts = array(); |
|
574 | + |
|
575 | + /** @type EE_Message_Resource_Manager $_message_resource_manager */ |
|
576 | + protected $_message_resource_manager; |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * EE_messages constructor. |
|
581 | + * |
|
582 | + * @deprecated 4.9.0 |
|
583 | + */ |
|
584 | + public function __construct() |
|
585 | + { |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * @param string $method |
|
591 | + */ |
|
592 | + public function _class_is_deprecated($method) |
|
593 | + { |
|
594 | + EE_Error::doing_it_wrong( |
|
595 | + 'EE_messages::' . $method, |
|
596 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
597 | + '4.9.0', |
|
598 | + '4.10.0.p' |
|
599 | + ); |
|
600 | + // Please use EE_Message_Resource_Manager instead |
|
601 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * @deprecated 4.9.0 |
|
607 | + * @param string $messenger_name |
|
608 | + * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
|
609 | + */ |
|
610 | + public function ensure_messenger_is_active($messenger_name) |
|
611 | + { |
|
612 | + // EE_messages has been deprecated |
|
613 | + $this->_class_is_deprecated(__FUNCTION__); |
|
614 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * @deprecated 4.9.0 |
|
620 | + * @param string $message_type message type name |
|
621 | + * @param $messenger |
|
622 | + * @return bool true if it got activated (or was active) and false if not. |
|
623 | + * @throws \EE_Error |
|
624 | + */ |
|
625 | + public function ensure_message_type_is_active($message_type, $messenger) |
|
626 | + { |
|
627 | + // EE_messages has been deprecated |
|
628 | + $this->_class_is_deprecated(__FUNCTION__); |
|
629 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * @deprecated 4.9.0 |
|
635 | + * @param string $messenger_name |
|
636 | + * @param array $mts_to_activate (optional) An array of message types to activate with this messenger. |
|
637 | + * If included we do NOT setup the default message types (assuming they |
|
638 | + * are already setup.) |
|
639 | + * @return boolean an array of generated templates or false if nothing generated/activated. |
|
640 | + */ |
|
641 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) |
|
642 | + { |
|
643 | + // EE_messages has been deprecated |
|
644 | + $this->_class_is_deprecated(__FUNCTION__); |
|
645 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @deprecated 4.9.0 |
|
651 | + * @param EE_messenger $messenger messenger used in trigger |
|
652 | + * @param EE_message_type $message_type message type used in trigger |
|
653 | + * |
|
654 | + * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
655 | + */ |
|
656 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
657 | + { |
|
658 | + // EE_messages has been deprecated |
|
659 | + $this->_class_is_deprecated(__FUNCTION__); |
|
660 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * @deprecated 4.9.0 |
|
666 | + * @param string $messenger |
|
667 | + * @return EE_messenger | null |
|
668 | + */ |
|
669 | + public function get_messenger_if_active($messenger) |
|
670 | + { |
|
671 | + // EE_messages has been deprecated |
|
672 | + $this->_class_is_deprecated(__FUNCTION__); |
|
673 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * @deprecated 4.9.0 |
|
679 | + * @param EE_Message $message |
|
680 | + * @return array An array with 'messenger' and 'message_type' as the index and the corresponding valid object if |
|
681 | + * available. |
|
682 | + * Eg. Valid Messenger and Message Type: |
|
683 | + * array( |
|
684 | + * 'messenger' => new EE_Email_messenger(), |
|
685 | + * 'message_type' => new EE_Registration_Approved_message_type() |
|
686 | + * ) |
|
687 | + * Valid Messenger and Invalid Message Type: |
|
688 | + * array( |
|
689 | + * 'messenger' => new EE_Email_messenger(), |
|
690 | + * 'message_type' => null |
|
691 | + * ) |
|
692 | + */ |
|
693 | + public function validate_for_use(EE_Message $message) |
|
694 | + { |
|
695 | + // EE_messages has been deprecated |
|
696 | + $this->_class_is_deprecated(__FUNCTION__); |
|
697 | + return array( |
|
698 | + 'messenger' => $message->messenger_object(), |
|
699 | + 'message_type' => $message->message_type_object(), |
|
700 | + ); |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @deprecated 4.9.0 |
|
706 | + * @param string $type What type of message are we sending (corresponds to message types) |
|
707 | + * @param mixed $vars Data being sent for parsing in the message |
|
708 | + * @param string $sending_messenger if included then we ONLY use the specified messenger for delivery. |
|
709 | + * Otherwise we cycle through all active messengers. |
|
710 | + * @param string $generating_messenger if included then this messenger is used for generating the message |
|
711 | + * templates (but not for sending). |
|
712 | + * @param string $context If included then only a message type for a specific context will be |
|
713 | + * generated. |
|
714 | + * @param bool $send Default TRUE. If false, then this will just return the generated |
|
715 | + * EE_messages objects which might be used by the trigger to setup a batch |
|
716 | + * message (typically html messenger uses it). |
|
717 | + * @return bool |
|
718 | + */ |
|
719 | + public function send_message( |
|
720 | + $type, |
|
721 | + $vars, |
|
722 | + $sending_messenger = '', |
|
723 | + $generating_messenger = '', |
|
724 | + $context = '', |
|
725 | + $send = true |
|
726 | + ) { |
|
727 | + // EE_messages has been deprecated |
|
728 | + $this->_class_is_deprecated(__FUNCTION__); |
|
729 | + /** @type EE_Messages_Processor $processor */ |
|
730 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
731 | + $error = false; |
|
732 | + // try to intelligently determine what method we'll call based on the incoming data. |
|
733 | + // if generating and sending are different then generate and send immediately. |
|
734 | + if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
735 | + // in the legacy system, when generating and sending were different, that means all the |
|
736 | + // vars are already in the request object. So let's just use that. |
|
737 | + try { |
|
738 | + /** @type EE_Message_To_Generate_From_Request $mtg */ |
|
739 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
740 | + $processor->generate_and_send_now($mtg); |
|
741 | + } catch (EE_Error $e) { |
|
742 | + $error_msg = __( |
|
743 | + 'Please note that a system message failed to send due to a technical issue.', |
|
744 | + 'event_espresso' |
|
745 | + ); |
|
746 | + // add specific message for developers if WP_DEBUG in on |
|
747 | + $error_msg .= '||' . $e->getMessage(); |
|
748 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
749 | + $error = true; |
|
750 | + } |
|
751 | + } else { |
|
752 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
753 | + // let's find out if there were any errors and how many successfully were queued. |
|
754 | + $count_errors = $processor->get_queue()->count_STS_in_queue( |
|
755 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
756 | + ); |
|
757 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
758 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
759 | + $count_errors = $count_errors + $count_retry; |
|
760 | + if ($count_errors > 0) { |
|
761 | + $error = true; |
|
762 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
763 | + $message = sprintf( |
|
764 | + __( |
|
765 | + 'There were %d errors and %d messages successfully queued for generation and sending', |
|
766 | + 'event_espresso' |
|
767 | + ), |
|
768 | + $count_errors, |
|
769 | + $count_queued |
|
770 | + ); |
|
771 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
772 | + $message = sprintf( |
|
773 | + __( |
|
774 | + 'There were %d errors and %d message successfully queued for generation.', |
|
775 | + 'event_espresso' |
|
776 | + ), |
|
777 | + $count_errors, |
|
778 | + $count_queued |
|
779 | + ); |
|
780 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
781 | + $message = sprintf( |
|
782 | + __( |
|
783 | + 'There was %d error and %d messages successfully queued for generation.', |
|
784 | + 'event_espresso' |
|
785 | + ), |
|
786 | + $count_errors, |
|
787 | + $count_queued |
|
788 | + ); |
|
789 | + } else { |
|
790 | + $message = sprintf( |
|
791 | + __( |
|
792 | + 'There was %d message that failed to be queued for generation.', |
|
793 | + 'event_espresso' |
|
794 | + ), |
|
795 | + $count_errors |
|
796 | + ); |
|
797 | + } |
|
798 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
799 | + } else { |
|
800 | + if ($count_queued === 1) { |
|
801 | + $message = sprintf( |
|
802 | + __( |
|
803 | + '%d message successfully queued for generation.', |
|
804 | + 'event_espresso' |
|
805 | + ), |
|
806 | + $count_queued |
|
807 | + ); |
|
808 | + } else { |
|
809 | + $message = sprintf( |
|
810 | + __( |
|
811 | + '%d messages were successfully queued for generation.', |
|
812 | + 'event_espresso' |
|
813 | + ), |
|
814 | + $count_queued |
|
815 | + ); |
|
816 | + } |
|
817 | + EE_Error::add_success($message); |
|
818 | + } |
|
819 | + } |
|
820 | + // if no error then return the generated message(s). |
|
821 | + if (! $error && ! $send) { |
|
822 | + $generated_queue = $processor->generate_queue(false); |
|
823 | + // get message and return. |
|
824 | + $generated_queue->get_message_repository()->rewind(); |
|
825 | + $messages = array(); |
|
826 | + while ($generated_queue->get_message_repository()->valid()) { |
|
827 | + $message = $generated_queue->get_message_repository()->current(); |
|
828 | + if ($message instanceof EE_Message) { |
|
829 | + // set properties that might be expected by add-ons (backward compat) |
|
830 | + $message->content = $message->content(); |
|
831 | + $message->template_pack = $message->get_template_pack(); |
|
832 | + $message->template_variation = $message->get_template_pack_variation(); |
|
833 | + $messages[] = $message; |
|
834 | + } |
|
835 | + $generated_queue->get_message_repository()->next(); |
|
836 | + } |
|
837 | + return $messages; |
|
838 | + } |
|
839 | + return $error ? false |
|
840 | + : true; // yeah backwards eh? Really what we're returning is if there is a total success for all the messages or not. We'll modify this once we get message recording in place. |
|
841 | + } |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * @deprecated 4.9.0 |
|
846 | + * @param string $type This should correspond with a valid message type |
|
847 | + * @param string $context This should correspond with a valid context for the message type |
|
848 | + * @param string $messenger This should correspond with a valid messenger. |
|
849 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
850 | + * preview |
|
851 | + * @return string The body of the message. |
|
852 | + */ |
|
853 | + public function preview_message($type, $context, $messenger, $send = false) |
|
854 | + { |
|
855 | + // EE_messages has been deprecated |
|
856 | + $this->_class_is_deprecated(__FUNCTION__); |
|
857 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * @since 4.5.0 |
|
863 | + * @deprecated 4.9.0 Moved to EED_Messages Module |
|
864 | + * @param string $messenger a string matching a valid active messenger in the system |
|
865 | + * @param string $message_type Although it seems contrary to the name of the method, a message type name is still |
|
866 | + * required to send along the message type to the messenger because this is used for |
|
867 | + * determining what specific variations might be loaded for the generated message. |
|
868 | + * @param stdClass $message a stdClass object in the format expected by the messenger. |
|
869 | + * |
|
870 | + * @return bool success or fail. |
|
871 | + */ |
|
872 | + public function send_message_with_messenger_only($messenger, $message_type, $message) |
|
873 | + { |
|
874 | + // EE_messages has been deprecated |
|
875 | + $this->_class_is_deprecated(__FUNCTION__); |
|
876 | + // setup for sending to new method. |
|
877 | + /** @type EE_Messages_Queue $queue */ |
|
878 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
879 | + // make sure we have a proper message object |
|
880 | + if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
881 | + $msg = EE_Message_Factory::create( |
|
882 | + array( |
|
883 | + 'MSG_messenger' => $messenger, |
|
884 | + 'MSG_message_type' => $message_type, |
|
885 | + 'MSG_content' => $message->content, |
|
886 | + 'MSG_subject' => $message->subject, |
|
887 | + ) |
|
888 | + ); |
|
889 | + } else { |
|
890 | + $msg = $message; |
|
891 | + } |
|
892 | + if (! $msg instanceof EE_Message) { |
|
893 | + return false; |
|
894 | + } |
|
895 | + // make sure any content in a content property (if not empty) is set on the MSG_content. |
|
896 | + if (! empty($msg->content)) { |
|
897 | + $msg->set('MSG_content', $msg->content); |
|
898 | + } |
|
899 | + $queue->add($msg); |
|
900 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * @deprecated 4.9.0 |
|
906 | + * @param $messenger |
|
907 | + * @param string $message_type message type that the templates are being created for |
|
908 | + * @param int $GRP_ID |
|
909 | + * @param bool $is_global |
|
910 | + * @return array|object if creation is successful then we return an array of info, otherwise an error_object is |
|
911 | + * returned. |
|
912 | + * @throws \EE_Error |
|
913 | + */ |
|
914 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) |
|
915 | + { |
|
916 | + // EE_messages has been deprecated |
|
917 | + $this->_class_is_deprecated(__FUNCTION__); |
|
918 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
919 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * @deprecated 4.9.0 |
|
925 | + * @param string $messenger_name name of EE_messenger |
|
926 | + * @param string $message_type_name name of EE_message_type |
|
927 | + * @return array |
|
928 | + */ |
|
929 | + public function get_fields($messenger_name, $message_type_name) |
|
930 | + { |
|
931 | + // EE_messages has been deprecated |
|
932 | + $this->_class_is_deprecated(__FUNCTION__); |
|
933 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
934 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * @deprecated 4.9.0 |
|
940 | + * @access public |
|
941 | + * @param string $type we can indicate just returning installed message types |
|
942 | + * or messengers (or both) via this parameter. |
|
943 | + * @param bool $skip_cache if true then we skip the cache and retrieve via files. |
|
944 | + * @return array multidimensional array of messenger and message_type objects |
|
945 | + * (messengers index, and message_type index); |
|
946 | + */ |
|
947 | + public function get_installed($type = 'all', $skip_cache = false) |
|
948 | + { |
|
949 | + // EE_messages has been deprecated |
|
950 | + $this->_class_is_deprecated(__FUNCTION__); |
|
951 | + if ($skip_cache) { |
|
952 | + $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
|
953 | + } |
|
954 | + switch ($type) { |
|
955 | + case 'messengers' : |
|
956 | + return array( |
|
957 | + 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
958 | + ); |
|
959 | + break; |
|
960 | + case 'message_types' : |
|
961 | + return array( |
|
962 | + 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
963 | + ); |
|
964 | + break; |
|
965 | + case 'all' : |
|
966 | + default : |
|
967 | + return array( |
|
968 | + 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
969 | + 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
970 | + ); |
|
971 | + break; |
|
972 | + } |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * @deprecated 4.9.0 |
|
978 | + * @return \EE_messenger[] |
|
979 | + */ |
|
980 | + public function get_active_messengers() |
|
981 | + { |
|
982 | + // EE_messages has been deprecated |
|
983 | + $this->_class_is_deprecated(__FUNCTION__); |
|
984 | + return $this->_message_resource_manager->active_messengers(); |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * @deprecated 4.9.0 |
|
990 | + * @return array array of message_type references (string) |
|
991 | + */ |
|
992 | + public function get_active_message_types() |
|
993 | + { |
|
994 | + // EE_messages has been deprecated |
|
995 | + $this->_class_is_deprecated(__FUNCTION__); |
|
996 | + return $this->_message_resource_manager->list_of_active_message_types(); |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + /** |
|
1001 | + * @deprecated 4.9.0 |
|
1002 | + * @return EE_message_type[] |
|
1003 | + */ |
|
1004 | + public function get_active_message_type_objects() |
|
1005 | + { |
|
1006 | + // EE_messages has been deprecated |
|
1007 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1008 | + return $this->_message_resource_manager->get_active_message_type_objects(); |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * @deprecated 4.9.0 |
|
1014 | + * @since 4.5.0 |
|
1015 | + * @param string $messenger The messenger being checked |
|
1016 | + * @return EE_message_type[] (or empty array if none present) |
|
1017 | + */ |
|
1018 | + public function get_active_message_types_per_messenger($messenger) |
|
1019 | + { |
|
1020 | + // EE_messages has been deprecated |
|
1021 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1022 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * @deprecated 4.9.0 |
|
1028 | + * @param string $messenger The string should correspond to the messenger (message types are |
|
1029 | + * @param string $message_type The string should correspond to a message type. |
|
1030 | + * @return EE_message_type|null |
|
1031 | + */ |
|
1032 | + public function get_active_message_type($messenger, $message_type) |
|
1033 | + { |
|
1034 | + // EE_messages has been deprecated |
|
1035 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1036 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
1037 | + } |
|
1038 | + |
|
1039 | + |
|
1040 | + /** |
|
1041 | + * @deprecated 4.9.0 |
|
1042 | + * @return array|\EE_message_type[] |
|
1043 | + */ |
|
1044 | + public function get_installed_message_types() |
|
1045 | + { |
|
1046 | + // EE_messages has been deprecated |
|
1047 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1048 | + return $this->_message_resource_manager->installed_message_types(); |
|
1049 | + } |
|
1050 | + |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * @deprecated 4.9.0 |
|
1054 | + * @return array |
|
1055 | + */ |
|
1056 | + public function get_installed_messengers() |
|
1057 | + { |
|
1058 | + // EE_messages has been deprecated |
|
1059 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1060 | + return $this->_message_resource_manager->installed_messengers(); |
|
1061 | + } |
|
1062 | + |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * @deprecated 4.9.0 |
|
1066 | + * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by |
|
1067 | + * message type. |
|
1068 | + * @return array |
|
1069 | + */ |
|
1070 | + public function get_all_contexts($slugs_only = true) |
|
1071 | + { |
|
1072 | + // EE_messages has been deprecated |
|
1073 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1074 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
1075 | + } |
|
1076 | 1076 | |
1077 | 1077 | |
1078 | 1078 | } |
@@ -1131,88 +1131,88 @@ discard block |
||
1131 | 1131 | |
1132 | 1132 | |
1133 | 1133 | add_filter( |
1134 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1135 | - function ($event_list_iframe_css) { |
|
1136 | - if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1137 | - return $event_list_iframe_css; |
|
1138 | - } |
|
1139 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1140 | - 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1141 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1142 | - '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1143 | - '4.9.14', |
|
1144 | - '5.0.0', |
|
1145 | - 'filter' |
|
1146 | - ); |
|
1147 | - return apply_filters( |
|
1148 | - 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1149 | - $event_list_iframe_css |
|
1150 | - ); |
|
1151 | - } |
|
1134 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1135 | + function ($event_list_iframe_css) { |
|
1136 | + if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1137 | + return $event_list_iframe_css; |
|
1138 | + } |
|
1139 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1140 | + 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1141 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1142 | + '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1143 | + '4.9.14', |
|
1144 | + '5.0.0', |
|
1145 | + 'filter' |
|
1146 | + ); |
|
1147 | + return apply_filters( |
|
1148 | + 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1149 | + $event_list_iframe_css |
|
1150 | + ); |
|
1151 | + } |
|
1152 | 1152 | ); |
1153 | 1153 | add_filter( |
1154 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1155 | - function ($event_list_iframe_js) { |
|
1156 | - if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1157 | - return $event_list_iframe_js; |
|
1158 | - } |
|
1159 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1160 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1161 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1162 | - '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1163 | - '4.9.14', |
|
1164 | - '5.0.0', |
|
1165 | - 'filter' |
|
1166 | - ); |
|
1167 | - return apply_filters( |
|
1168 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1169 | - $event_list_iframe_js |
|
1170 | - ); |
|
1171 | - } |
|
1154 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1155 | + function ($event_list_iframe_js) { |
|
1156 | + if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1157 | + return $event_list_iframe_js; |
|
1158 | + } |
|
1159 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1160 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1161 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1162 | + '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1163 | + '4.9.14', |
|
1164 | + '5.0.0', |
|
1165 | + 'filter' |
|
1166 | + ); |
|
1167 | + return apply_filters( |
|
1168 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1169 | + $event_list_iframe_js |
|
1170 | + ); |
|
1171 | + } |
|
1172 | 1172 | ); |
1173 | 1173 | add_action( |
1174 | - 'AHEE__EE_Capabilities__addCaps__complete', |
|
1175 | - function ($capabilities_map) { |
|
1176 | - if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1177 | - return; |
|
1178 | - } |
|
1179 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1180 | - 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1181 | - 'AHEE__EE_Capabilities__addCaps__complete', |
|
1182 | - '\EE_Capabilities::addCaps()', |
|
1183 | - '4.9.42', |
|
1184 | - '5.0.0' |
|
1185 | - ); |
|
1186 | - do_action( |
|
1187 | - 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1188 | - $capabilities_map |
|
1189 | - ); |
|
1190 | - } |
|
1174 | + 'AHEE__EE_Capabilities__addCaps__complete', |
|
1175 | + function ($capabilities_map) { |
|
1176 | + if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1177 | + return; |
|
1178 | + } |
|
1179 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1180 | + 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1181 | + 'AHEE__EE_Capabilities__addCaps__complete', |
|
1182 | + '\EE_Capabilities::addCaps()', |
|
1183 | + '4.9.42', |
|
1184 | + '5.0.0' |
|
1185 | + ); |
|
1186 | + do_action( |
|
1187 | + 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1188 | + $capabilities_map |
|
1189 | + ); |
|
1190 | + } |
|
1191 | 1191 | ); |
1192 | 1192 | |
1193 | 1193 | add_filter( |
1194 | - 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1195 | - function ($existing_attendee, $registration, $attendee_data) { |
|
1196 | - if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1197 | - return $existing_attendee; |
|
1198 | - } |
|
1199 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1200 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1201 | - 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1202 | - '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()', |
|
1203 | - '4.9.34', |
|
1204 | - '5.0.0', |
|
1205 | - 'filter' |
|
1206 | - ); |
|
1207 | - return apply_filters( |
|
1208 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1209 | - $existing_attendee, |
|
1210 | - $registration, |
|
1211 | - $attendee_data |
|
1212 | - ); |
|
1213 | - }, |
|
1214 | - 10, |
|
1215 | - 3 |
|
1194 | + 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1195 | + function ($existing_attendee, $registration, $attendee_data) { |
|
1196 | + if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1197 | + return $existing_attendee; |
|
1198 | + } |
|
1199 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1200 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1201 | + 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1202 | + '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()', |
|
1203 | + '4.9.34', |
|
1204 | + '5.0.0', |
|
1205 | + 'filter' |
|
1206 | + ); |
|
1207 | + return apply_filters( |
|
1208 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1209 | + $existing_attendee, |
|
1210 | + $registration, |
|
1211 | + $attendee_data |
|
1212 | + ); |
|
1213 | + }, |
|
1214 | + 10, |
|
1215 | + 3 |
|
1216 | 1216 | ); |
1217 | 1217 | |
1218 | 1218 | /** |
@@ -1223,88 +1223,88 @@ discard block |
||
1223 | 1223 | class EE_Event_List_Query extends WP_Query |
1224 | 1224 | { |
1225 | 1225 | |
1226 | - private $title; |
|
1227 | - |
|
1228 | - private $css_class; |
|
1229 | - |
|
1230 | - private $category_slug; |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * EE_Event_List_Query constructor. |
|
1234 | - * |
|
1235 | - * @param array $args |
|
1236 | - */ |
|
1237 | - public function __construct($args = array()) |
|
1238 | - { |
|
1239 | - \EE_Error::doing_it_wrong( |
|
1240 | - __METHOD__, |
|
1241 | - __( |
|
1242 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1243 | - 'event_espresso' |
|
1244 | - ), |
|
1245 | - '4.9.27', |
|
1246 | - '5.0.0' |
|
1247 | - ); |
|
1248 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1249 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1250 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1251 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1252 | - // the current "page" we are viewing |
|
1253 | - $paged = max(1, get_query_var('paged')); |
|
1254 | - // Force these args |
|
1255 | - $args = array_merge( |
|
1256 | - $args, |
|
1257 | - array( |
|
1258 | - 'post_type' => 'espresso_events', |
|
1259 | - 'posts_per_page' => $limit, |
|
1260 | - 'update_post_term_cache' => false, |
|
1261 | - 'update_post_meta_cache' => false, |
|
1262 | - 'paged' => $paged, |
|
1263 | - 'offset' => ($paged - 1) * $limit, |
|
1264 | - ) |
|
1265 | - ); |
|
1266 | - // run the query |
|
1267 | - parent::__construct($args); |
|
1268 | - } |
|
1269 | - |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * event_list_title |
|
1273 | - * |
|
1274 | - * @param string $event_list_title |
|
1275 | - * @return string |
|
1276 | - */ |
|
1277 | - public function event_list_title($event_list_title = '') |
|
1278 | - { |
|
1279 | - if (! empty($this->title)) { |
|
1280 | - return $this->title; |
|
1281 | - } |
|
1282 | - return $event_list_title; |
|
1283 | - } |
|
1284 | - |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * event_list_css |
|
1288 | - * |
|
1289 | - * @param string $event_list_css |
|
1290 | - * @return string |
|
1291 | - */ |
|
1292 | - public function event_list_css($event_list_css = '') |
|
1293 | - { |
|
1294 | - $event_list_css .= ! empty($event_list_css) |
|
1295 | - ? ' ' |
|
1296 | - : ''; |
|
1297 | - $event_list_css .= ! empty($this->css_class) |
|
1298 | - ? $this->css_class |
|
1299 | - : ''; |
|
1300 | - $event_list_css .= ! empty($event_list_css) |
|
1301 | - ? ' ' |
|
1302 | - : ''; |
|
1303 | - $event_list_css .= ! empty($this->category_slug) |
|
1304 | - ? $this->category_slug |
|
1305 | - : ''; |
|
1306 | - return $event_list_css; |
|
1307 | - } |
|
1226 | + private $title; |
|
1227 | + |
|
1228 | + private $css_class; |
|
1229 | + |
|
1230 | + private $category_slug; |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * EE_Event_List_Query constructor. |
|
1234 | + * |
|
1235 | + * @param array $args |
|
1236 | + */ |
|
1237 | + public function __construct($args = array()) |
|
1238 | + { |
|
1239 | + \EE_Error::doing_it_wrong( |
|
1240 | + __METHOD__, |
|
1241 | + __( |
|
1242 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1243 | + 'event_espresso' |
|
1244 | + ), |
|
1245 | + '4.9.27', |
|
1246 | + '5.0.0' |
|
1247 | + ); |
|
1248 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1249 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1250 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1251 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1252 | + // the current "page" we are viewing |
|
1253 | + $paged = max(1, get_query_var('paged')); |
|
1254 | + // Force these args |
|
1255 | + $args = array_merge( |
|
1256 | + $args, |
|
1257 | + array( |
|
1258 | + 'post_type' => 'espresso_events', |
|
1259 | + 'posts_per_page' => $limit, |
|
1260 | + 'update_post_term_cache' => false, |
|
1261 | + 'update_post_meta_cache' => false, |
|
1262 | + 'paged' => $paged, |
|
1263 | + 'offset' => ($paged - 1) * $limit, |
|
1264 | + ) |
|
1265 | + ); |
|
1266 | + // run the query |
|
1267 | + parent::__construct($args); |
|
1268 | + } |
|
1269 | + |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * event_list_title |
|
1273 | + * |
|
1274 | + * @param string $event_list_title |
|
1275 | + * @return string |
|
1276 | + */ |
|
1277 | + public function event_list_title($event_list_title = '') |
|
1278 | + { |
|
1279 | + if (! empty($this->title)) { |
|
1280 | + return $this->title; |
|
1281 | + } |
|
1282 | + return $event_list_title; |
|
1283 | + } |
|
1284 | + |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * event_list_css |
|
1288 | + * |
|
1289 | + * @param string $event_list_css |
|
1290 | + * @return string |
|
1291 | + */ |
|
1292 | + public function event_list_css($event_list_css = '') |
|
1293 | + { |
|
1294 | + $event_list_css .= ! empty($event_list_css) |
|
1295 | + ? ' ' |
|
1296 | + : ''; |
|
1297 | + $event_list_css .= ! empty($this->css_class) |
|
1298 | + ? $this->css_class |
|
1299 | + : ''; |
|
1300 | + $event_list_css .= ! empty($event_list_css) |
|
1301 | + ? ' ' |
|
1302 | + : ''; |
|
1303 | + $event_list_css .= ! empty($this->category_slug) |
|
1304 | + ? $this->category_slug |
|
1305 | + : ''; |
|
1306 | + return $event_list_css; |
|
1307 | + } |
|
1308 | 1308 | |
1309 | 1309 | } |
1310 | 1310 | |
@@ -1321,75 +1321,75 @@ discard block |
||
1321 | 1321 | { |
1322 | 1322 | |
1323 | 1323 | |
1324 | - /** |
|
1325 | - * class constructor |
|
1326 | - * |
|
1327 | - * @deprecated 4.9.59.p |
|
1328 | - */ |
|
1329 | - public function __construct() |
|
1330 | - { |
|
1331 | - EE_Error::doing_it_wrong( |
|
1332 | - __METHOD__, |
|
1333 | - sprintf( |
|
1334 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1335 | - __CLASS__, |
|
1336 | - 'EventEspresso\core\services\licensing\LicenseServices' |
|
1337 | - ), |
|
1338 | - '4.9.59.p' |
|
1339 | - ); |
|
1340 | - } |
|
1341 | - |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * The purpose of this function is to display information about Event Espresso data collection |
|
1345 | - * and a optin selection for extra data collecting by users. |
|
1346 | - * |
|
1347 | - * @param bool $extra |
|
1348 | - * @return string html. |
|
1349 | - * @deprecated 4.9.59.p |
|
1350 | - */ |
|
1351 | - public static function espresso_data_collection_optin_text($extra = true) |
|
1352 | - { |
|
1353 | - EE_Error::doing_it_wrong( |
|
1354 | - __METHOD__, |
|
1355 | - sprintf( |
|
1356 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1357 | - __METHOD__, |
|
1358 | - 'EventEspresso\core\domain\services\Stats::optinText' |
|
1359 | - ), |
|
1360 | - '4.9.59.p' |
|
1361 | - ); |
|
1362 | - Stats::optinText($extra); |
|
1363 | - } |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
1367 | - * |
|
1368 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
1369 | - * identify plugins. Defaults to core update |
|
1370 | - * @return boolean True if update available, false if not. |
|
1371 | - * @deprecated 4.9.59.p |
|
1372 | - */ |
|
1373 | - public static function is_update_available($basename = '') |
|
1374 | - { |
|
1375 | - EE_Error::doing_it_wrong( |
|
1376 | - __METHOD__, |
|
1377 | - sprintf( |
|
1378 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1379 | - __METHOD__, |
|
1380 | - 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
1381 | - ), |
|
1382 | - '4.9.59.p' |
|
1383 | - ); |
|
1384 | - return LicenseService::isUpdateAvailable($basename); |
|
1385 | - } |
|
1324 | + /** |
|
1325 | + * class constructor |
|
1326 | + * |
|
1327 | + * @deprecated 4.9.59.p |
|
1328 | + */ |
|
1329 | + public function __construct() |
|
1330 | + { |
|
1331 | + EE_Error::doing_it_wrong( |
|
1332 | + __METHOD__, |
|
1333 | + sprintf( |
|
1334 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1335 | + __CLASS__, |
|
1336 | + 'EventEspresso\core\services\licensing\LicenseServices' |
|
1337 | + ), |
|
1338 | + '4.9.59.p' |
|
1339 | + ); |
|
1340 | + } |
|
1341 | + |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * The purpose of this function is to display information about Event Espresso data collection |
|
1345 | + * and a optin selection for extra data collecting by users. |
|
1346 | + * |
|
1347 | + * @param bool $extra |
|
1348 | + * @return string html. |
|
1349 | + * @deprecated 4.9.59.p |
|
1350 | + */ |
|
1351 | + public static function espresso_data_collection_optin_text($extra = true) |
|
1352 | + { |
|
1353 | + EE_Error::doing_it_wrong( |
|
1354 | + __METHOD__, |
|
1355 | + sprintf( |
|
1356 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1357 | + __METHOD__, |
|
1358 | + 'EventEspresso\core\domain\services\Stats::optinText' |
|
1359 | + ), |
|
1360 | + '4.9.59.p' |
|
1361 | + ); |
|
1362 | + Stats::optinText($extra); |
|
1363 | + } |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
1367 | + * |
|
1368 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
1369 | + * identify plugins. Defaults to core update |
|
1370 | + * @return boolean True if update available, false if not. |
|
1371 | + * @deprecated 4.9.59.p |
|
1372 | + */ |
|
1373 | + public static function is_update_available($basename = '') |
|
1374 | + { |
|
1375 | + EE_Error::doing_it_wrong( |
|
1376 | + __METHOD__, |
|
1377 | + sprintf( |
|
1378 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1379 | + __METHOD__, |
|
1380 | + 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
1381 | + ), |
|
1382 | + '4.9.59.p' |
|
1383 | + ); |
|
1384 | + return LicenseService::isUpdateAvailable($basename); |
|
1385 | + } |
|
1386 | 1386 | } |
1387 | 1387 | |
1388 | 1388 | add_filter( |
1389 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
1390 | - 'ee_deprecated_registrations_report_csv_legacy_fields', |
|
1391 | - 10, |
|
1392 | - 2 |
|
1389 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
1390 | + 'ee_deprecated_registrations_report_csv_legacy_fields', |
|
1391 | + 10, |
|
1392 | + 2 |
|
1393 | 1393 | ); |
1394 | 1394 | /** |
1395 | 1395 | * Filters the CSV row to make it appear like the old labels (which were "$pretty_name[$field_name]"). |
@@ -1406,96 +1406,96 @@ discard block |
||
1406 | 1406 | */ |
1407 | 1407 | function ee_deprecated_registrations_report_csv_legacy_fields($csv_row_data, $reg_row) |
1408 | 1408 | { |
1409 | - // no need for all this if nobody is using the deprecated filter |
|
1410 | - if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) { |
|
1411 | - EE_Error::doing_it_wrong( |
|
1412 | - __FUNCTION__, |
|
1413 | - sprintf( |
|
1414 | - // EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too. |
|
1415 | - _x( |
|
1416 | - 'The filter "%1$s" has been deprecated. Please use "%2$s" instead.', |
|
1417 | - 'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.', |
|
1418 | - 'event_espresso' |
|
1419 | - ), |
|
1420 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
1421 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array' |
|
1422 | - ), |
|
1423 | - '4.9.69.p', |
|
1424 | - '4.9.75.p' |
|
1425 | - ); |
|
1426 | - // there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format! |
|
1427 | - // first: what model fields might be used as column headers? (whose format we need to change) |
|
1428 | - $model_fields = array_merge( |
|
1429 | - EEM_Registration::instance()->field_settings(), |
|
1430 | - EEM_Attendee::instance()->field_settings() |
|
1431 | - ); |
|
1432 | - // create an array that uses the legacy column headers/labels. |
|
1433 | - $new_csv_row = array(); |
|
1434 | - foreach ($csv_row_data as $label => $value) { |
|
1435 | - $new_label = $label; |
|
1436 | - foreach ($model_fields as $field) { |
|
1437 | - if ($label === EEH_Export::get_column_name_for_field($field)) { |
|
1438 | - // re-add the old field name |
|
1439 | - $new_label = $label . '[' . $field->get_name() . ']'; |
|
1440 | - break; |
|
1441 | - } |
|
1442 | - } |
|
1443 | - $new_csv_row[$new_label] = $value; |
|
1444 | - } |
|
1445 | - // before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()` |
|
1446 | - // to create the old column names, because that's what's in the row temporarily |
|
1447 | - add_filter( |
|
1448 | - 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
1449 | - '__return_true', |
|
1450 | - 777 |
|
1451 | - ); |
|
1452 | - // now, those old filters can be run on this data. Have fun! |
|
1453 | - /** |
|
1454 | - * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead. |
|
1455 | - * |
|
1456 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
1457 | - * This can be used to add or remote columns from the CSV file, or change their values. * |
|
1458 | - * Note: it has this name because originally that's where this filter resided, |
|
1459 | - * and we've left its name as-is for backward compatibility. |
|
1460 | - * Note when using: all rows in the CSV should have the same columns. |
|
1461 | - * |
|
1462 | - * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
1463 | - * in this row |
|
1464 | - * @param array $reg_row is the row from the database's wp_esp_registration table |
|
1465 | - */ |
|
1466 | - $updated_row = apply_filters( |
|
1467 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
1468 | - $new_csv_row, |
|
1469 | - $reg_row |
|
1470 | - ); |
|
1471 | - |
|
1472 | - // ok now we can revert to normal for EEH_Export::get_column_name_for_field(). |
|
1473 | - remove_filter( |
|
1474 | - 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
1475 | - '__return_true', |
|
1476 | - 777 |
|
1477 | - ); |
|
1478 | - |
|
1479 | - // great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels. |
|
1480 | - $updated_and_restored_row = array(); |
|
1481 | - foreach ($updated_row as $label => $value) { |
|
1482 | - $matches = array(); |
|
1483 | - if (preg_match( |
|
1484 | - '~([^\[]*)\[(.*)\]~', |
|
1485 | - $label, |
|
1486 | - $matches |
|
1487 | - ) |
|
1488 | - && isset( |
|
1489 | - $matches[0], |
|
1490 | - $matches[1], |
|
1491 | - $matches[2] |
|
1492 | - ) |
|
1493 | - ) { |
|
1494 | - $label = $matches[1]; |
|
1495 | - } |
|
1496 | - $updated_and_restored_row[$label] = $value; |
|
1497 | - } |
|
1498 | - $csv_row_data = $updated_and_restored_row; |
|
1499 | - } |
|
1500 | - return $csv_row_data; |
|
1409 | + // no need for all this if nobody is using the deprecated filter |
|
1410 | + if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) { |
|
1411 | + EE_Error::doing_it_wrong( |
|
1412 | + __FUNCTION__, |
|
1413 | + sprintf( |
|
1414 | + // EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too. |
|
1415 | + _x( |
|
1416 | + 'The filter "%1$s" has been deprecated. Please use "%2$s" instead.', |
|
1417 | + 'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.', |
|
1418 | + 'event_espresso' |
|
1419 | + ), |
|
1420 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
1421 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array' |
|
1422 | + ), |
|
1423 | + '4.9.69.p', |
|
1424 | + '4.9.75.p' |
|
1425 | + ); |
|
1426 | + // there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format! |
|
1427 | + // first: what model fields might be used as column headers? (whose format we need to change) |
|
1428 | + $model_fields = array_merge( |
|
1429 | + EEM_Registration::instance()->field_settings(), |
|
1430 | + EEM_Attendee::instance()->field_settings() |
|
1431 | + ); |
|
1432 | + // create an array that uses the legacy column headers/labels. |
|
1433 | + $new_csv_row = array(); |
|
1434 | + foreach ($csv_row_data as $label => $value) { |
|
1435 | + $new_label = $label; |
|
1436 | + foreach ($model_fields as $field) { |
|
1437 | + if ($label === EEH_Export::get_column_name_for_field($field)) { |
|
1438 | + // re-add the old field name |
|
1439 | + $new_label = $label . '[' . $field->get_name() . ']'; |
|
1440 | + break; |
|
1441 | + } |
|
1442 | + } |
|
1443 | + $new_csv_row[$new_label] = $value; |
|
1444 | + } |
|
1445 | + // before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()` |
|
1446 | + // to create the old column names, because that's what's in the row temporarily |
|
1447 | + add_filter( |
|
1448 | + 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
1449 | + '__return_true', |
|
1450 | + 777 |
|
1451 | + ); |
|
1452 | + // now, those old filters can be run on this data. Have fun! |
|
1453 | + /** |
|
1454 | + * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead. |
|
1455 | + * |
|
1456 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
1457 | + * This can be used to add or remote columns from the CSV file, or change their values. * |
|
1458 | + * Note: it has this name because originally that's where this filter resided, |
|
1459 | + * and we've left its name as-is for backward compatibility. |
|
1460 | + * Note when using: all rows in the CSV should have the same columns. |
|
1461 | + * |
|
1462 | + * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
1463 | + * in this row |
|
1464 | + * @param array $reg_row is the row from the database's wp_esp_registration table |
|
1465 | + */ |
|
1466 | + $updated_row = apply_filters( |
|
1467 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
1468 | + $new_csv_row, |
|
1469 | + $reg_row |
|
1470 | + ); |
|
1471 | + |
|
1472 | + // ok now we can revert to normal for EEH_Export::get_column_name_for_field(). |
|
1473 | + remove_filter( |
|
1474 | + 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
1475 | + '__return_true', |
|
1476 | + 777 |
|
1477 | + ); |
|
1478 | + |
|
1479 | + // great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels. |
|
1480 | + $updated_and_restored_row = array(); |
|
1481 | + foreach ($updated_row as $label => $value) { |
|
1482 | + $matches = array(); |
|
1483 | + if (preg_match( |
|
1484 | + '~([^\[]*)\[(.*)\]~', |
|
1485 | + $label, |
|
1486 | + $matches |
|
1487 | + ) |
|
1488 | + && isset( |
|
1489 | + $matches[0], |
|
1490 | + $matches[1], |
|
1491 | + $matches[2] |
|
1492 | + ) |
|
1493 | + ) { |
|
1494 | + $label = $matches[1]; |
|
1495 | + } |
|
1496 | + $updated_and_restored_row[$label] = $value; |
|
1497 | + } |
|
1498 | + $csv_row_data = $updated_and_restored_row; |
|
1499 | + } |
|
1500 | + return $csv_row_data; |
|
1501 | 1501 | } |
1502 | 1502 | \ No newline at end of file |
@@ -84,6 +84,7 @@ |
||
84 | 84 | * |
85 | 85 | * @access public |
86 | 86 | * @param mixed |
87 | + * @param string $info |
|
87 | 88 | * @return null | object |
88 | 89 | */ |
89 | 90 | public function get_by_info($info) |
@@ -16,160 +16,160 @@ |
||
16 | 16 | abstract class EE_Object_Collection extends SplObjectStorage implements EEI_Collection |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
21 | - * this should be set from within the child class constructor |
|
22 | - * |
|
23 | - * @type string $interface |
|
24 | - */ |
|
25 | - protected $interface; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * add |
|
30 | - * |
|
31 | - * attaches an object to the Collection |
|
32 | - * and sets any supplied data associated with the current iterator entry |
|
33 | - * by calling EE_Object_Collection::set_info() |
|
34 | - * |
|
35 | - * @access public |
|
36 | - * @param object $object |
|
37 | - * @param mixed $info |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - public function add($object, $info = null) |
|
41 | - { |
|
42 | - $class = $this->interface; |
|
43 | - if (! $object instanceof $class) { |
|
44 | - return false; |
|
45 | - } |
|
46 | - $this->attach($object); |
|
47 | - $this->set_info($object, $info); |
|
48 | - return $this->contains($object); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * set_info |
|
54 | - * |
|
55 | - * Sets the data associated with an object in the Collection |
|
56 | - * if no $info is supplied, then the spl_object_hash() is used |
|
57 | - * |
|
58 | - * @access public |
|
59 | - * @param object $object |
|
60 | - * @param mixed $info |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function set_info($object, $info = null) |
|
64 | - { |
|
65 | - $info = ! empty($info) ? $info : spl_object_hash($object); |
|
66 | - $this->rewind(); |
|
67 | - while ($this->valid()) { |
|
68 | - if ($object == $this->current()) { |
|
69 | - $this->setInfo($info); |
|
70 | - $this->rewind(); |
|
71 | - return true; |
|
72 | - } |
|
73 | - $this->next(); |
|
74 | - } |
|
75 | - return false; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * get_by_info |
|
81 | - * |
|
82 | - * finds and returns an object in the Collection based on the info that was set using addObject() |
|
83 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
84 | - * |
|
85 | - * @access public |
|
86 | - * @param mixed |
|
87 | - * @return null | object |
|
88 | - */ |
|
89 | - public function get_by_info($info) |
|
90 | - { |
|
91 | - $this->rewind(); |
|
92 | - while ($this->valid()) { |
|
93 | - if ($info === $this->getInfo()) { |
|
94 | - $object = $this->current(); |
|
95 | - $this->rewind(); |
|
96 | - return $object; |
|
97 | - } |
|
98 | - $this->next(); |
|
99 | - } |
|
100 | - return null; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * has |
|
106 | - * |
|
107 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
108 | - * |
|
109 | - * @access public |
|
110 | - * @param object $object |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function has($object) |
|
114 | - { |
|
115 | - return $this->contains($object); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * remove |
|
121 | - * |
|
122 | - * detaches an object from the Collection |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param $object |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - public function remove($object) |
|
129 | - { |
|
130 | - $this->detach($object); |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * set_current |
|
137 | - * |
|
138 | - * advances pointer to the provided object |
|
139 | - * |
|
140 | - * @access public |
|
141 | - * @param $object |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function set_current($object) |
|
145 | - { |
|
146 | - $this->rewind(); |
|
147 | - while ($this->valid()) { |
|
148 | - if ($this->current() === $object) { |
|
149 | - break; |
|
150 | - } |
|
151 | - $this->next(); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * set_current_by_info |
|
158 | - * |
|
159 | - * advances pointer to the object whose info matches that which was provided |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @param $info |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function set_current_by_info($info) |
|
166 | - { |
|
167 | - $this->rewind(); |
|
168 | - while ($this->valid()) { |
|
169 | - if ($info === $this->getInfo()) { |
|
170 | - break; |
|
171 | - } |
|
172 | - $this->next(); |
|
173 | - } |
|
174 | - } |
|
19 | + /** |
|
20 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
21 | + * this should be set from within the child class constructor |
|
22 | + * |
|
23 | + * @type string $interface |
|
24 | + */ |
|
25 | + protected $interface; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * add |
|
30 | + * |
|
31 | + * attaches an object to the Collection |
|
32 | + * and sets any supplied data associated with the current iterator entry |
|
33 | + * by calling EE_Object_Collection::set_info() |
|
34 | + * |
|
35 | + * @access public |
|
36 | + * @param object $object |
|
37 | + * @param mixed $info |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + public function add($object, $info = null) |
|
41 | + { |
|
42 | + $class = $this->interface; |
|
43 | + if (! $object instanceof $class) { |
|
44 | + return false; |
|
45 | + } |
|
46 | + $this->attach($object); |
|
47 | + $this->set_info($object, $info); |
|
48 | + return $this->contains($object); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * set_info |
|
54 | + * |
|
55 | + * Sets the data associated with an object in the Collection |
|
56 | + * if no $info is supplied, then the spl_object_hash() is used |
|
57 | + * |
|
58 | + * @access public |
|
59 | + * @param object $object |
|
60 | + * @param mixed $info |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function set_info($object, $info = null) |
|
64 | + { |
|
65 | + $info = ! empty($info) ? $info : spl_object_hash($object); |
|
66 | + $this->rewind(); |
|
67 | + while ($this->valid()) { |
|
68 | + if ($object == $this->current()) { |
|
69 | + $this->setInfo($info); |
|
70 | + $this->rewind(); |
|
71 | + return true; |
|
72 | + } |
|
73 | + $this->next(); |
|
74 | + } |
|
75 | + return false; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * get_by_info |
|
81 | + * |
|
82 | + * finds and returns an object in the Collection based on the info that was set using addObject() |
|
83 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
84 | + * |
|
85 | + * @access public |
|
86 | + * @param mixed |
|
87 | + * @return null | object |
|
88 | + */ |
|
89 | + public function get_by_info($info) |
|
90 | + { |
|
91 | + $this->rewind(); |
|
92 | + while ($this->valid()) { |
|
93 | + if ($info === $this->getInfo()) { |
|
94 | + $object = $this->current(); |
|
95 | + $this->rewind(); |
|
96 | + return $object; |
|
97 | + } |
|
98 | + $this->next(); |
|
99 | + } |
|
100 | + return null; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * has |
|
106 | + * |
|
107 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
108 | + * |
|
109 | + * @access public |
|
110 | + * @param object $object |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function has($object) |
|
114 | + { |
|
115 | + return $this->contains($object); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * remove |
|
121 | + * |
|
122 | + * detaches an object from the Collection |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param $object |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + public function remove($object) |
|
129 | + { |
|
130 | + $this->detach($object); |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * set_current |
|
137 | + * |
|
138 | + * advances pointer to the provided object |
|
139 | + * |
|
140 | + * @access public |
|
141 | + * @param $object |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function set_current($object) |
|
145 | + { |
|
146 | + $this->rewind(); |
|
147 | + while ($this->valid()) { |
|
148 | + if ($this->current() === $object) { |
|
149 | + break; |
|
150 | + } |
|
151 | + $this->next(); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * set_current_by_info |
|
158 | + * |
|
159 | + * advances pointer to the object whose info matches that which was provided |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @param $info |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function set_current_by_info($info) |
|
166 | + { |
|
167 | + $this->rewind(); |
|
168 | + while ($this->valid()) { |
|
169 | + if ($info === $this->getInfo()) { |
|
170 | + break; |
|
171 | + } |
|
172 | + $this->next(); |
|
173 | + } |
|
174 | + } |
|
175 | 175 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | public function add($object, $info = null) |
41 | 41 | { |
42 | 42 | $class = $this->interface; |
43 | - if (! $object instanceof $class) { |
|
43 | + if ( ! $object instanceof $class) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | $this->attach($object); |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @param mixed $opt_group |
779 | 779 | * @param mixed $QSOs |
780 | - * @param mixed $answer |
|
780 | + * @param string $answer |
|
781 | 781 | * @param boolean $use_html_entities |
782 | 782 | * @return string |
783 | 783 | */ |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | /** |
1135 | 1135 | * prep_required |
1136 | 1136 | * @param string|array $required |
1137 | - * @return array |
|
1137 | + * @return string |
|
1138 | 1138 | */ |
1139 | 1139 | public static function prep_required($required = array()) |
1140 | 1140 | { |
@@ -1187,8 +1187,8 @@ discard block |
||
1187 | 1187 | |
1188 | 1188 | /** |
1189 | 1189 | * _load_system_dropdowns |
1190 | - * @param array $QFI |
|
1191 | - * @return array |
|
1190 | + * @param EE_Question_Form_Input $QFI |
|
1191 | + * @return EE_Question_Form_Input |
|
1192 | 1192 | */ |
1193 | 1193 | private static function _load_system_dropdowns($QFI) |
1194 | 1194 | { |
@@ -1491,7 +1491,7 @@ discard block |
||
1491 | 1491 | * @param string $nonce_action - if using nonces |
1492 | 1492 | * @param bool|string $input_only - whether to print form header and footer. TRUE returns the input without the form |
1493 | 1493 | * @param string $extra_attributes - any extra attributes that need to be attached to the form input |
1494 | - * @return void |
|
1494 | + * @return string |
|
1495 | 1495 | */ |
1496 | 1496 | public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '') |
1497 | 1497 | { |
@@ -29,1034 +29,1034 @@ discard block |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Generates HTML for the forms used on admin pages |
|
34 | - * |
|
35 | - * |
|
36 | - * @static |
|
37 | - * @access public |
|
38 | - * @param array $input_vars - array of input field details |
|
39 | - * format: |
|
40 | - * $template_form_fields['field-id'] = array( |
|
41 | - * 'name' => 'name_attribute', |
|
42 | - * 'label' => __('Field Label', 'event_espresso'), //or false |
|
43 | - * 'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', 'checkbox', 'wp_editor' |
|
44 | - * 'type' => 'int', //what "type" the value is (i.e. string, int etc) |
|
45 | - * 'required' => false, //boolean for whether the field is required |
|
46 | - * 'validation' => true, //boolean, whether to validate the field (todo) |
|
47 | - * 'value' => 'some_value_for_field', //what value is used for field |
|
48 | - * 'format' => '%d', //what format the value is (%d, %f, or %s) |
|
49 | - * 'db-col' => 'column_in_db' //used to indicate which column the field corresponds with in the db |
|
50 | - * 'options' => optiona, optionb || array('value' => 'label', '') //if the input type is "select", this allows you to set the args for the different <option> tags. |
|
51 | - * 'tabindex' => 1 //this allows you to set the tabindex for the field. |
|
52 | - * 'append_content' => '' //this allows you to send in html content to append to the field. |
|
53 | - * ) |
|
54 | - * @param array $id - used for defining unique identifiers for the form. |
|
55 | - * @return string |
|
56 | - * @todo: at some point we can break this down into other static methods to abstract it a bit better. |
|
57 | - */ |
|
58 | - public static function get_form_fields($input_vars = array(), $id = false) |
|
59 | - { |
|
60 | - |
|
61 | - if (empty($input_vars)) { |
|
62 | - EE_Error::add_error(__('missing required variables for the form field generator', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
63 | - return false; |
|
64 | - } |
|
65 | - |
|
66 | - // if you don't behave - this is what you're gonna get !!! |
|
67 | - $close = true; |
|
68 | - $output = '<ul>'; // this is for using built-in wp styles... watch carefully... |
|
69 | - |
|
70 | - // cycle thru inputs |
|
71 | - foreach ($input_vars as $input_key => $input_value) { |
|
72 | - $defaults = array( |
|
73 | - 'name' => $input_key, |
|
74 | - 'label' => __('No label', 'event_espresso'), |
|
75 | - 'input' => 'hidden', |
|
76 | - 'type' => 'int', |
|
77 | - 'required' => false, |
|
78 | - 'validation' => true, |
|
79 | - 'value' => 'some_value_for_field', |
|
80 | - 'format' => '%d', |
|
81 | - 'db-col' => 'column_in_db', |
|
82 | - 'options' => array(), |
|
83 | - 'tabindex' => '', |
|
84 | - 'append_content' => '' |
|
85 | - ); |
|
86 | - |
|
87 | - $input_value = wp_parse_args($input_value, $defaults); |
|
88 | - |
|
89 | - // required fields get a * |
|
90 | - $required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': '; |
|
91 | - // and the css class "required" |
|
92 | - $css_class = isset($input_value['css_class']) ? $input_value['css_class'] : ''; |
|
93 | - $styles = $input_value['required'] ? 'required ' . $css_class : $css_class; |
|
94 | - |
|
95 | - $field_id = ($id) ? $id . '-' . $input_key : $input_key; |
|
96 | - $tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : ''; |
|
97 | - |
|
98 | - // rows or cols? |
|
99 | - $rows = isset($input_value['rows']) ? $input_value['rows'] : '10'; |
|
100 | - $cols = isset($input_value['cols']) ? $input_value['cols'] : '80'; |
|
101 | - |
|
102 | - // any content? |
|
103 | - $append_content = $input_value['append_content']; |
|
104 | - |
|
105 | - $output .= (!$close) ? '<ul>' : ''; |
|
106 | - $output .= '<li>'; |
|
107 | - |
|
108 | - // what type of input are we dealing with ? |
|
109 | - switch ($input_value['input']) { |
|
110 | - // text inputs |
|
111 | - case 'text': |
|
112 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
113 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
114 | - break; |
|
115 | - |
|
116 | - // dropdowns |
|
117 | - case 'select': |
|
118 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
119 | - $output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
120 | - |
|
121 | - if (is_array($input_value['options'])) { |
|
122 | - $options = $input_value['options']; |
|
123 | - } else { |
|
124 | - $options = explode(',', $input_value['options']); |
|
125 | - } |
|
126 | - |
|
127 | - foreach ($options as $key => $value) { |
|
128 | - $selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : ''; |
|
129 | - // $key = str_replace( ' ', '_', sanitize_key( $value )); |
|
130 | - $output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>'; |
|
131 | - } |
|
132 | - $output .= "\n\t\t\t" . '</select>'; |
|
133 | - |
|
134 | - break; |
|
135 | - |
|
136 | - case 'textarea': |
|
137 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
138 | - $output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>'; |
|
139 | - break; |
|
140 | - |
|
141 | - case 'hidden': |
|
142 | - $close = false; |
|
143 | - $output .= "</li></ul>"; |
|
144 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">'; |
|
145 | - break; |
|
146 | - |
|
147 | - case 'checkbox': |
|
148 | - $checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : ''; |
|
149 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
150 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />'; |
|
151 | - break; |
|
152 | - |
|
153 | - case 'wp_editor': |
|
154 | - $close = false; |
|
155 | - $editor_settings = array( |
|
156 | - 'textarea_name' => $input_value['name'], |
|
157 | - 'textarea_rows' => $rows, |
|
158 | - 'editor_class' => $styles, |
|
159 | - 'tabindex' => $input_value['tabindex'] |
|
160 | - ); |
|
161 | - $output .= '</li>'; |
|
162 | - $output .= '</ul>'; |
|
163 | - $output .= '<h4>' . $input_value['label'] . '</h4>'; |
|
164 | - if ($append_content) { |
|
165 | - $output .= $append_content; |
|
166 | - } |
|
167 | - ob_start(); |
|
168 | - wp_editor($input_value['value'], $field_id, $editor_settings); |
|
169 | - $editor = ob_get_contents(); |
|
170 | - ob_end_clean(); |
|
171 | - $output .= $editor; |
|
172 | - break; |
|
173 | - } |
|
174 | - if ($append_content && $input_value['input'] !== 'wp_editor') { |
|
175 | - $output .= $append_content; |
|
176 | - } |
|
177 | - $output .= ($close) ? '</li>' : ''; |
|
178 | - } // end foreach( $input_vars as $input_key => $input_value ) |
|
179 | - $output .= ($close) ? '</ul>' : ''; |
|
180 | - |
|
181 | - return $output; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * form_fields_array |
|
186 | - * This utility function assembles form fields from a given structured array with field information. |
|
187 | - * //TODO: This is an alternate generator that we may want to use instead. |
|
188 | - * |
|
189 | - * @param array $fields structured array of fields to assemble in the following format: |
|
190 | - * [field_name] => array( |
|
191 | - * ['label'] => 'label for field', |
|
192 | - * ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select type of field you can indicated the labels for each option via this index |
|
193 | - * ['extra_desc'] => 'extra description for the field', //optional |
|
194 | - * ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults to text |
|
195 | - * ['value'] => 'value that goes in the field', //(if multi then this is an array of values and the 'default' paramater will be used for what is selected) |
|
196 | - * ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)', |
|
197 | - * ['class'] => 'name-of-class(es)-for-input', |
|
198 | - * ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi select type of field you can indicate the css class for each option via this index. |
|
199 | - * ['id'] => 'css-id-for-input') //defaults to 'field_name' |
|
200 | - * ['unique_id'] => 1 //defaults to empty string. This is useful for when the fields generated are going to be used in a loop and you want to make sure that the field identifiers are unique from each other. |
|
201 | - * ['dimensions'] => array(100,300), //defaults to empty array. This is used by field types such as textarea to indicate cols/rows. |
|
202 | - * ['tabindex'] => '' //this allows you to set the tabindex for the field. |
|
203 | - * ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally contain an array of arguments for the editor setup. |
|
204 | - * |
|
205 | - * @return array an array of inputs for form indexed by field name, and in the following structure: |
|
206 | - * [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}' |
|
207 | - */ |
|
208 | - public static function get_form_fields_array($fields) |
|
209 | - { |
|
210 | - |
|
211 | - $form_fields = array(); |
|
212 | - $fields = (array) $fields; |
|
213 | - |
|
214 | - foreach ($fields as $field_name => $field_atts) { |
|
215 | - // defaults: |
|
216 | - $defaults = array( |
|
217 | - 'label' => '', |
|
218 | - 'labels' => '', |
|
219 | - 'extra_desc' => '', |
|
220 | - 'type' => 'text', |
|
221 | - 'value' => '', |
|
222 | - 'default' => '', |
|
223 | - 'class' => '', |
|
224 | - 'classes' => '', |
|
225 | - 'id' => $field_name, |
|
226 | - 'unique_id' => '', |
|
227 | - 'dimensions' => array('10', '5'), |
|
228 | - 'tabindex' => '', |
|
229 | - 'wpeditor_args' => array() |
|
230 | - ); |
|
231 | - // merge defaults with passed arguments |
|
232 | - $_fields = wp_parse_args($field_atts, $defaults); |
|
233 | - extract($_fields); |
|
234 | - // generate label |
|
235 | - $label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>'; |
|
236 | - // generate field name |
|
237 | - $f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
238 | - |
|
239 | - // tabindex |
|
240 | - $tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : ''; |
|
241 | - |
|
242 | - // we determine what we're building based on the type |
|
243 | - switch ($type) { |
|
244 | - case 'textarea': |
|
245 | - $fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>'; |
|
246 | - $fld .= $extra_desc; |
|
247 | - break; |
|
248 | - |
|
249 | - case 'checkbox': |
|
250 | - $c_input = ''; |
|
251 | - if (is_array($value)) { |
|
252 | - foreach ($value as $key => $val) { |
|
253 | - $c_id = $field_name . '_' . $value; |
|
254 | - $c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : ''; |
|
255 | - $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
256 | - $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
257 | - $c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
258 | - } |
|
259 | - $fld = $c_input; |
|
260 | - } else { |
|
261 | - $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
262 | - $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
263 | - } |
|
264 | - break; |
|
265 | - |
|
266 | - case 'radio': |
|
267 | - $c_input = ''; |
|
268 | - if (is_array($value)) { |
|
269 | - foreach ($value as $key => $val) { |
|
270 | - $c_id = $field_name . '_' . $value; |
|
271 | - $c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : ''; |
|
272 | - $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
273 | - $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
274 | - $c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
275 | - } |
|
276 | - $fld = $c_input; |
|
277 | - } else { |
|
278 | - $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
279 | - $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
280 | - } |
|
281 | - break; |
|
282 | - |
|
283 | - case 'hidden': |
|
284 | - $fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n"; |
|
285 | - break; |
|
286 | - |
|
287 | - case 'select': |
|
288 | - $fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n"; |
|
289 | - foreach ($value as $key => $val) { |
|
290 | - $checked = !empty($default) && $default == $val ? ' selected="selected"' : ''; |
|
291 | - $fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n"; |
|
292 | - } |
|
293 | - $fld .= '</select>'; |
|
294 | - break; |
|
295 | - |
|
296 | - case 'wp_editor': |
|
297 | - $editor_settings = array( |
|
298 | - 'textarea_name' => $f_name, |
|
299 | - 'textarea_rows' => $dimensions[1], |
|
300 | - 'editor_class' => $class, |
|
301 | - 'tabindex' => $tabindex |
|
302 | - ); |
|
303 | - $editor_settings = array_merge($wpeditor_args, $editor_settings); |
|
304 | - ob_start(); |
|
305 | - wp_editor($value, $id, $editor_settings); |
|
306 | - $editor = ob_get_contents(); |
|
307 | - ob_end_clean(); |
|
308 | - $fld = $editor; |
|
309 | - break; |
|
310 | - |
|
311 | - default: // 'text fields' |
|
312 | - $fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n"; |
|
313 | - $fld .= $extra_desc; |
|
314 | - } |
|
315 | - |
|
316 | - $form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld ); |
|
317 | - } |
|
318 | - |
|
319 | - return $form_fields; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * espresso admin page select_input |
|
329 | - * Turns an array into a select fields |
|
330 | - * |
|
331 | - * @static |
|
332 | - * @access public |
|
333 | - * @param string $name field name |
|
334 | - * @param array $values option values, numbered array starting at 0, where each value is an array with a key 'text' (meaning text to display' and 'id' (meaning the internal value) |
|
335 | - * eg: array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or as an array of key-value pairs, where the key is to be used for the |
|
336 | - * select input's name, and the value will be the text shown to the user. Optionally you can also include an additional key of "class" which will add a specific class to the option for that value. |
|
337 | - * @param string $default default value |
|
338 | - * @param string $parameters extra paramaters |
|
339 | - * @param string $class css class |
|
340 | - * @param boolean $autosize whether to autosize the select or not |
|
341 | - * @return string html string for the select input |
|
342 | - */ |
|
343 | - public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
|
344 | - { |
|
345 | - // if $values was submitted in the wrong format, convert it over |
|
346 | - if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) { |
|
347 | - $converted_values = array(); |
|
348 | - foreach ($values as $id => $text) { |
|
349 | - $converted_values[] = array('id' => $id,'text' => $text); |
|
350 | - } |
|
351 | - $values = $converted_values; |
|
352 | - } |
|
353 | - |
|
354 | - $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"'; |
|
355 | - // Debug |
|
356 | - // EEH_Debug_Tools::printr( $values, '$values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
357 | - if (EEH_Formatter::ee_tep_not_null($parameters)) { |
|
358 | - $field .= ' ' . $parameters; |
|
359 | - } |
|
360 | - if ($autosize) { |
|
361 | - $size = 'med'; |
|
362 | - for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
|
363 | - if ($values[ $ii ]['text']) { |
|
364 | - if (strlen($values[ $ii ]['text']) > 5) { |
|
365 | - $size = 'wide'; |
|
366 | - } |
|
367 | - } |
|
368 | - } |
|
369 | - } else { |
|
370 | - $size = ''; |
|
371 | - } |
|
372 | - |
|
373 | - $field .= ' class="' . $class . ' ' . $size . '">'; |
|
374 | - |
|
375 | - if (empty($default) && isset($GLOBALS[ $name ])) { |
|
376 | - $default = stripslashes($GLOBALS[ $name ]); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
|
381 | - $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
382 | - if ($default == $values[ $i ]['id']) { |
|
383 | - $field .= ' selected = "selected"'; |
|
384 | - } |
|
385 | - if (isset($values[ $i ]['class'])) { |
|
386 | - $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
387 | - } |
|
388 | - $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
389 | - } |
|
390 | - $field .= '</select>'; |
|
391 | - |
|
392 | - return $field; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * generate_question_groups_html |
|
402 | - * |
|
403 | - * @param string $question_groups |
|
404 | - * @return string HTML |
|
405 | - */ |
|
406 | - public static function generate_question_groups_html($question_groups = array(), $group_wrapper = 'fieldset') |
|
407 | - { |
|
408 | - |
|
409 | - $html = ''; |
|
410 | - $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
411 | - $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
412 | - |
|
413 | - if (! empty($question_groups)) { |
|
414 | - // EEH_Debug_Tools::printr( $question_groups, '$question_groups <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
415 | - // loop thru question groups |
|
416 | - foreach ($question_groups as $QSG) { |
|
417 | - // check that questions exist |
|
418 | - if (! empty($QSG['QSG_questions'])) { |
|
419 | - // use fieldsets |
|
420 | - $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">'; |
|
421 | - // group_name |
|
422 | - $html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : ''; |
|
423 | - // group_desc |
|
424 | - $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : ''; |
|
425 | - |
|
426 | - $html .= $before_question_group_questions; |
|
427 | - // loop thru questions |
|
428 | - foreach ($QSG['QSG_questions'] as $question) { |
|
32 | + /** |
|
33 | + * Generates HTML for the forms used on admin pages |
|
34 | + * |
|
35 | + * |
|
36 | + * @static |
|
37 | + * @access public |
|
38 | + * @param array $input_vars - array of input field details |
|
39 | + * format: |
|
40 | + * $template_form_fields['field-id'] = array( |
|
41 | + * 'name' => 'name_attribute', |
|
42 | + * 'label' => __('Field Label', 'event_espresso'), //or false |
|
43 | + * 'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', 'checkbox', 'wp_editor' |
|
44 | + * 'type' => 'int', //what "type" the value is (i.e. string, int etc) |
|
45 | + * 'required' => false, //boolean for whether the field is required |
|
46 | + * 'validation' => true, //boolean, whether to validate the field (todo) |
|
47 | + * 'value' => 'some_value_for_field', //what value is used for field |
|
48 | + * 'format' => '%d', //what format the value is (%d, %f, or %s) |
|
49 | + * 'db-col' => 'column_in_db' //used to indicate which column the field corresponds with in the db |
|
50 | + * 'options' => optiona, optionb || array('value' => 'label', '') //if the input type is "select", this allows you to set the args for the different <option> tags. |
|
51 | + * 'tabindex' => 1 //this allows you to set the tabindex for the field. |
|
52 | + * 'append_content' => '' //this allows you to send in html content to append to the field. |
|
53 | + * ) |
|
54 | + * @param array $id - used for defining unique identifiers for the form. |
|
55 | + * @return string |
|
56 | + * @todo: at some point we can break this down into other static methods to abstract it a bit better. |
|
57 | + */ |
|
58 | + public static function get_form_fields($input_vars = array(), $id = false) |
|
59 | + { |
|
60 | + |
|
61 | + if (empty($input_vars)) { |
|
62 | + EE_Error::add_error(__('missing required variables for the form field generator', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
63 | + return false; |
|
64 | + } |
|
65 | + |
|
66 | + // if you don't behave - this is what you're gonna get !!! |
|
67 | + $close = true; |
|
68 | + $output = '<ul>'; // this is for using built-in wp styles... watch carefully... |
|
69 | + |
|
70 | + // cycle thru inputs |
|
71 | + foreach ($input_vars as $input_key => $input_value) { |
|
72 | + $defaults = array( |
|
73 | + 'name' => $input_key, |
|
74 | + 'label' => __('No label', 'event_espresso'), |
|
75 | + 'input' => 'hidden', |
|
76 | + 'type' => 'int', |
|
77 | + 'required' => false, |
|
78 | + 'validation' => true, |
|
79 | + 'value' => 'some_value_for_field', |
|
80 | + 'format' => '%d', |
|
81 | + 'db-col' => 'column_in_db', |
|
82 | + 'options' => array(), |
|
83 | + 'tabindex' => '', |
|
84 | + 'append_content' => '' |
|
85 | + ); |
|
86 | + |
|
87 | + $input_value = wp_parse_args($input_value, $defaults); |
|
88 | + |
|
89 | + // required fields get a * |
|
90 | + $required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': '; |
|
91 | + // and the css class "required" |
|
92 | + $css_class = isset($input_value['css_class']) ? $input_value['css_class'] : ''; |
|
93 | + $styles = $input_value['required'] ? 'required ' . $css_class : $css_class; |
|
94 | + |
|
95 | + $field_id = ($id) ? $id . '-' . $input_key : $input_key; |
|
96 | + $tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : ''; |
|
97 | + |
|
98 | + // rows or cols? |
|
99 | + $rows = isset($input_value['rows']) ? $input_value['rows'] : '10'; |
|
100 | + $cols = isset($input_value['cols']) ? $input_value['cols'] : '80'; |
|
101 | + |
|
102 | + // any content? |
|
103 | + $append_content = $input_value['append_content']; |
|
104 | + |
|
105 | + $output .= (!$close) ? '<ul>' : ''; |
|
106 | + $output .= '<li>'; |
|
107 | + |
|
108 | + // what type of input are we dealing with ? |
|
109 | + switch ($input_value['input']) { |
|
110 | + // text inputs |
|
111 | + case 'text': |
|
112 | + $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
113 | + $output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
114 | + break; |
|
115 | + |
|
116 | + // dropdowns |
|
117 | + case 'select': |
|
118 | + $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
119 | + $output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
120 | + |
|
121 | + if (is_array($input_value['options'])) { |
|
122 | + $options = $input_value['options']; |
|
123 | + } else { |
|
124 | + $options = explode(',', $input_value['options']); |
|
125 | + } |
|
126 | + |
|
127 | + foreach ($options as $key => $value) { |
|
128 | + $selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : ''; |
|
129 | + // $key = str_replace( ' ', '_', sanitize_key( $value )); |
|
130 | + $output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>'; |
|
131 | + } |
|
132 | + $output .= "\n\t\t\t" . '</select>'; |
|
133 | + |
|
134 | + break; |
|
135 | + |
|
136 | + case 'textarea': |
|
137 | + $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
138 | + $output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>'; |
|
139 | + break; |
|
140 | + |
|
141 | + case 'hidden': |
|
142 | + $close = false; |
|
143 | + $output .= "</li></ul>"; |
|
144 | + $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">'; |
|
145 | + break; |
|
146 | + |
|
147 | + case 'checkbox': |
|
148 | + $checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : ''; |
|
149 | + $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
150 | + $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />'; |
|
151 | + break; |
|
152 | + |
|
153 | + case 'wp_editor': |
|
154 | + $close = false; |
|
155 | + $editor_settings = array( |
|
156 | + 'textarea_name' => $input_value['name'], |
|
157 | + 'textarea_rows' => $rows, |
|
158 | + 'editor_class' => $styles, |
|
159 | + 'tabindex' => $input_value['tabindex'] |
|
160 | + ); |
|
161 | + $output .= '</li>'; |
|
162 | + $output .= '</ul>'; |
|
163 | + $output .= '<h4>' . $input_value['label'] . '</h4>'; |
|
164 | + if ($append_content) { |
|
165 | + $output .= $append_content; |
|
166 | + } |
|
167 | + ob_start(); |
|
168 | + wp_editor($input_value['value'], $field_id, $editor_settings); |
|
169 | + $editor = ob_get_contents(); |
|
170 | + ob_end_clean(); |
|
171 | + $output .= $editor; |
|
172 | + break; |
|
173 | + } |
|
174 | + if ($append_content && $input_value['input'] !== 'wp_editor') { |
|
175 | + $output .= $append_content; |
|
176 | + } |
|
177 | + $output .= ($close) ? '</li>' : ''; |
|
178 | + } // end foreach( $input_vars as $input_key => $input_value ) |
|
179 | + $output .= ($close) ? '</ul>' : ''; |
|
180 | + |
|
181 | + return $output; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * form_fields_array |
|
186 | + * This utility function assembles form fields from a given structured array with field information. |
|
187 | + * //TODO: This is an alternate generator that we may want to use instead. |
|
188 | + * |
|
189 | + * @param array $fields structured array of fields to assemble in the following format: |
|
190 | + * [field_name] => array( |
|
191 | + * ['label'] => 'label for field', |
|
192 | + * ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select type of field you can indicated the labels for each option via this index |
|
193 | + * ['extra_desc'] => 'extra description for the field', //optional |
|
194 | + * ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults to text |
|
195 | + * ['value'] => 'value that goes in the field', //(if multi then this is an array of values and the 'default' paramater will be used for what is selected) |
|
196 | + * ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)', |
|
197 | + * ['class'] => 'name-of-class(es)-for-input', |
|
198 | + * ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi select type of field you can indicate the css class for each option via this index. |
|
199 | + * ['id'] => 'css-id-for-input') //defaults to 'field_name' |
|
200 | + * ['unique_id'] => 1 //defaults to empty string. This is useful for when the fields generated are going to be used in a loop and you want to make sure that the field identifiers are unique from each other. |
|
201 | + * ['dimensions'] => array(100,300), //defaults to empty array. This is used by field types such as textarea to indicate cols/rows. |
|
202 | + * ['tabindex'] => '' //this allows you to set the tabindex for the field. |
|
203 | + * ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally contain an array of arguments for the editor setup. |
|
204 | + * |
|
205 | + * @return array an array of inputs for form indexed by field name, and in the following structure: |
|
206 | + * [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}' |
|
207 | + */ |
|
208 | + public static function get_form_fields_array($fields) |
|
209 | + { |
|
210 | + |
|
211 | + $form_fields = array(); |
|
212 | + $fields = (array) $fields; |
|
213 | + |
|
214 | + foreach ($fields as $field_name => $field_atts) { |
|
215 | + // defaults: |
|
216 | + $defaults = array( |
|
217 | + 'label' => '', |
|
218 | + 'labels' => '', |
|
219 | + 'extra_desc' => '', |
|
220 | + 'type' => 'text', |
|
221 | + 'value' => '', |
|
222 | + 'default' => '', |
|
223 | + 'class' => '', |
|
224 | + 'classes' => '', |
|
225 | + 'id' => $field_name, |
|
226 | + 'unique_id' => '', |
|
227 | + 'dimensions' => array('10', '5'), |
|
228 | + 'tabindex' => '', |
|
229 | + 'wpeditor_args' => array() |
|
230 | + ); |
|
231 | + // merge defaults with passed arguments |
|
232 | + $_fields = wp_parse_args($field_atts, $defaults); |
|
233 | + extract($_fields); |
|
234 | + // generate label |
|
235 | + $label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>'; |
|
236 | + // generate field name |
|
237 | + $f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
238 | + |
|
239 | + // tabindex |
|
240 | + $tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : ''; |
|
241 | + |
|
242 | + // we determine what we're building based on the type |
|
243 | + switch ($type) { |
|
244 | + case 'textarea': |
|
245 | + $fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>'; |
|
246 | + $fld .= $extra_desc; |
|
247 | + break; |
|
248 | + |
|
249 | + case 'checkbox': |
|
250 | + $c_input = ''; |
|
251 | + if (is_array($value)) { |
|
252 | + foreach ($value as $key => $val) { |
|
253 | + $c_id = $field_name . '_' . $value; |
|
254 | + $c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : ''; |
|
255 | + $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
256 | + $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
257 | + $c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
258 | + } |
|
259 | + $fld = $c_input; |
|
260 | + } else { |
|
261 | + $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
262 | + $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
263 | + } |
|
264 | + break; |
|
265 | + |
|
266 | + case 'radio': |
|
267 | + $c_input = ''; |
|
268 | + if (is_array($value)) { |
|
269 | + foreach ($value as $key => $val) { |
|
270 | + $c_id = $field_name . '_' . $value; |
|
271 | + $c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : ''; |
|
272 | + $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
273 | + $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
274 | + $c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
275 | + } |
|
276 | + $fld = $c_input; |
|
277 | + } else { |
|
278 | + $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
279 | + $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
280 | + } |
|
281 | + break; |
|
282 | + |
|
283 | + case 'hidden': |
|
284 | + $fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n"; |
|
285 | + break; |
|
286 | + |
|
287 | + case 'select': |
|
288 | + $fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n"; |
|
289 | + foreach ($value as $key => $val) { |
|
290 | + $checked = !empty($default) && $default == $val ? ' selected="selected"' : ''; |
|
291 | + $fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n"; |
|
292 | + } |
|
293 | + $fld .= '</select>'; |
|
294 | + break; |
|
295 | + |
|
296 | + case 'wp_editor': |
|
297 | + $editor_settings = array( |
|
298 | + 'textarea_name' => $f_name, |
|
299 | + 'textarea_rows' => $dimensions[1], |
|
300 | + 'editor_class' => $class, |
|
301 | + 'tabindex' => $tabindex |
|
302 | + ); |
|
303 | + $editor_settings = array_merge($wpeditor_args, $editor_settings); |
|
304 | + ob_start(); |
|
305 | + wp_editor($value, $id, $editor_settings); |
|
306 | + $editor = ob_get_contents(); |
|
307 | + ob_end_clean(); |
|
308 | + $fld = $editor; |
|
309 | + break; |
|
310 | + |
|
311 | + default: // 'text fields' |
|
312 | + $fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n"; |
|
313 | + $fld .= $extra_desc; |
|
314 | + } |
|
315 | + |
|
316 | + $form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld ); |
|
317 | + } |
|
318 | + |
|
319 | + return $form_fields; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * espresso admin page select_input |
|
329 | + * Turns an array into a select fields |
|
330 | + * |
|
331 | + * @static |
|
332 | + * @access public |
|
333 | + * @param string $name field name |
|
334 | + * @param array $values option values, numbered array starting at 0, where each value is an array with a key 'text' (meaning text to display' and 'id' (meaning the internal value) |
|
335 | + * eg: array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or as an array of key-value pairs, where the key is to be used for the |
|
336 | + * select input's name, and the value will be the text shown to the user. Optionally you can also include an additional key of "class" which will add a specific class to the option for that value. |
|
337 | + * @param string $default default value |
|
338 | + * @param string $parameters extra paramaters |
|
339 | + * @param string $class css class |
|
340 | + * @param boolean $autosize whether to autosize the select or not |
|
341 | + * @return string html string for the select input |
|
342 | + */ |
|
343 | + public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
|
344 | + { |
|
345 | + // if $values was submitted in the wrong format, convert it over |
|
346 | + if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) { |
|
347 | + $converted_values = array(); |
|
348 | + foreach ($values as $id => $text) { |
|
349 | + $converted_values[] = array('id' => $id,'text' => $text); |
|
350 | + } |
|
351 | + $values = $converted_values; |
|
352 | + } |
|
353 | + |
|
354 | + $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"'; |
|
355 | + // Debug |
|
356 | + // EEH_Debug_Tools::printr( $values, '$values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
357 | + if (EEH_Formatter::ee_tep_not_null($parameters)) { |
|
358 | + $field .= ' ' . $parameters; |
|
359 | + } |
|
360 | + if ($autosize) { |
|
361 | + $size = 'med'; |
|
362 | + for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
|
363 | + if ($values[ $ii ]['text']) { |
|
364 | + if (strlen($values[ $ii ]['text']) > 5) { |
|
365 | + $size = 'wide'; |
|
366 | + } |
|
367 | + } |
|
368 | + } |
|
369 | + } else { |
|
370 | + $size = ''; |
|
371 | + } |
|
372 | + |
|
373 | + $field .= ' class="' . $class . ' ' . $size . '">'; |
|
374 | + |
|
375 | + if (empty($default) && isset($GLOBALS[ $name ])) { |
|
376 | + $default = stripslashes($GLOBALS[ $name ]); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
|
381 | + $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
382 | + if ($default == $values[ $i ]['id']) { |
|
383 | + $field .= ' selected = "selected"'; |
|
384 | + } |
|
385 | + if (isset($values[ $i ]['class'])) { |
|
386 | + $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
387 | + } |
|
388 | + $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
389 | + } |
|
390 | + $field .= '</select>'; |
|
391 | + |
|
392 | + return $field; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * generate_question_groups_html |
|
402 | + * |
|
403 | + * @param string $question_groups |
|
404 | + * @return string HTML |
|
405 | + */ |
|
406 | + public static function generate_question_groups_html($question_groups = array(), $group_wrapper = 'fieldset') |
|
407 | + { |
|
408 | + |
|
409 | + $html = ''; |
|
410 | + $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
411 | + $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
412 | + |
|
413 | + if (! empty($question_groups)) { |
|
414 | + // EEH_Debug_Tools::printr( $question_groups, '$question_groups <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
415 | + // loop thru question groups |
|
416 | + foreach ($question_groups as $QSG) { |
|
417 | + // check that questions exist |
|
418 | + if (! empty($QSG['QSG_questions'])) { |
|
419 | + // use fieldsets |
|
420 | + $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">'; |
|
421 | + // group_name |
|
422 | + $html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : ''; |
|
423 | + // group_desc |
|
424 | + $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : ''; |
|
425 | + |
|
426 | + $html .= $before_question_group_questions; |
|
427 | + // loop thru questions |
|
428 | + foreach ($QSG['QSG_questions'] as $question) { |
|
429 | 429 | // EEH_Debug_Tools::printr( $question, '$question <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
430 | - $QFI = new EE_Question_Form_Input( |
|
431 | - $question['qst_obj'], |
|
432 | - $question['ans_obj'], |
|
433 | - $question |
|
434 | - ); |
|
435 | - $html .= self::generate_form_input($QFI); |
|
436 | - } |
|
437 | - $html .= $after_question_group_questions; |
|
438 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
439 | - } |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - return $html; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * generate_question_groups_html |
|
450 | - * |
|
451 | - * @param array $question_groups |
|
452 | - * @param array $q_meta |
|
453 | - * @param bool $from_admin |
|
454 | - * @param string $group_wrapper |
|
455 | - * @return string HTML |
|
456 | - */ |
|
457 | - public static function generate_question_groups_html2($question_groups = array(), $q_meta = array(), $from_admin = false, $group_wrapper = 'fieldset') |
|
458 | - { |
|
459 | - |
|
460 | - $html = ''; |
|
461 | - $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
462 | - $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
463 | - |
|
464 | - $default_q_meta = array( |
|
465 | - 'att_nmbr' => 1, |
|
466 | - 'ticket_id' => '', |
|
467 | - 'input_name' => '', |
|
468 | - 'input_id' => '', |
|
469 | - 'input_class' => '' |
|
470 | - ); |
|
471 | - $q_meta = array_merge($default_q_meta, $q_meta); |
|
472 | - // EEH_Debug_Tools::printr( $q_meta, '$q_meta <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
473 | - |
|
474 | - if (! empty($question_groups)) { |
|
430 | + $QFI = new EE_Question_Form_Input( |
|
431 | + $question['qst_obj'], |
|
432 | + $question['ans_obj'], |
|
433 | + $question |
|
434 | + ); |
|
435 | + $html .= self::generate_form_input($QFI); |
|
436 | + } |
|
437 | + $html .= $after_question_group_questions; |
|
438 | + $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
439 | + } |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + return $html; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * generate_question_groups_html |
|
450 | + * |
|
451 | + * @param array $question_groups |
|
452 | + * @param array $q_meta |
|
453 | + * @param bool $from_admin |
|
454 | + * @param string $group_wrapper |
|
455 | + * @return string HTML |
|
456 | + */ |
|
457 | + public static function generate_question_groups_html2($question_groups = array(), $q_meta = array(), $from_admin = false, $group_wrapper = 'fieldset') |
|
458 | + { |
|
459 | + |
|
460 | + $html = ''; |
|
461 | + $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
462 | + $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
463 | + |
|
464 | + $default_q_meta = array( |
|
465 | + 'att_nmbr' => 1, |
|
466 | + 'ticket_id' => '', |
|
467 | + 'input_name' => '', |
|
468 | + 'input_id' => '', |
|
469 | + 'input_class' => '' |
|
470 | + ); |
|
471 | + $q_meta = array_merge($default_q_meta, $q_meta); |
|
472 | + // EEH_Debug_Tools::printr( $q_meta, '$q_meta <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
473 | + |
|
474 | + if (! empty($question_groups)) { |
|
475 | 475 | // EEH_Debug_Tools::printr( $question_groups, '$question_groups <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
476 | - // loop thru question groups |
|
477 | - foreach ($question_groups as $QSG) { |
|
478 | - if ($QSG instanceof EE_Question_Group) { |
|
479 | - // check that questions exist |
|
480 | - |
|
481 | - $where = array( 'QST_deleted' => 0 ); |
|
482 | - if (! $from_admin) { |
|
483 | - $where['QST_admin_only'] = 0; |
|
484 | - } |
|
485 | - $questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' ))); |
|
486 | - if (! empty($questions)) { |
|
487 | - // use fieldsets |
|
488 | - $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">'; |
|
489 | - // group_name |
|
490 | - if ($QSG->show_group_name()) { |
|
491 | - $html .= "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>'; |
|
492 | - } |
|
493 | - // group_desc |
|
494 | - if ($QSG->show_group_desc()) { |
|
495 | - $html .= '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>'; |
|
496 | - } |
|
497 | - |
|
498 | - $html .= $before_question_group_questions; |
|
499 | - // loop thru questions |
|
500 | - foreach ($questions as $QST) { |
|
501 | - $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID(); |
|
502 | - |
|
503 | - $answer = null; |
|
504 | - |
|
505 | - if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
506 | - // check for answer in $_GET in case we are reprocessing a form after an error |
|
507 | - if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) { |
|
508 | - $answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]); |
|
509 | - } |
|
510 | - } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
|
511 | - // attendee data from the session |
|
512 | - $answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - $QFI = new EE_Question_Form_Input( |
|
518 | - $QST, |
|
519 | - EE_Answer::new_instance(array( |
|
520 | - 'ANS_ID' => 0, |
|
521 | - 'QST_ID' => 0, |
|
522 | - 'REG_ID' => 0, |
|
523 | - 'ANS_value' => $answer |
|
524 | - )), |
|
525 | - $q_meta |
|
526 | - ); |
|
527 | - // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
528 | - $html .= self::generate_form_input($QFI); |
|
529 | - } |
|
530 | - $html .= $after_question_group_questions; |
|
531 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
532 | - } |
|
533 | - } |
|
534 | - } |
|
535 | - } |
|
536 | - return $html; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * generate_form_input |
|
546 | - * |
|
547 | - * @param EE_Question_Form_Input $QFI |
|
548 | - * @return string HTML |
|
549 | - */ |
|
550 | - public static function generate_form_input(EE_Question_Form_Input $QFI) |
|
551 | - { |
|
552 | - if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) { |
|
553 | - return ''; |
|
554 | - } |
|
555 | - |
|
556 | - $QFI = self::_load_system_dropdowns($QFI); |
|
557 | - $QFI = self::_load_specialized_dropdowns($QFI); |
|
558 | - |
|
559 | - // we also need to verify |
|
560 | - |
|
561 | - $display_text = $QFI->get('QST_display_text'); |
|
562 | - $input_name = $QFI->get('QST_input_name'); |
|
563 | - $answer = EE_Registry::instance()->REQ->is_set($input_name) ? EE_Registry::instance()->REQ->get($input_name) : $QFI->get('ANS_value'); |
|
564 | - $input_id = $QFI->get('QST_input_id'); |
|
565 | - $input_class = $QFI->get('QST_input_class'); |
|
476 | + // loop thru question groups |
|
477 | + foreach ($question_groups as $QSG) { |
|
478 | + if ($QSG instanceof EE_Question_Group) { |
|
479 | + // check that questions exist |
|
480 | + |
|
481 | + $where = array( 'QST_deleted' => 0 ); |
|
482 | + if (! $from_admin) { |
|
483 | + $where['QST_admin_only'] = 0; |
|
484 | + } |
|
485 | + $questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' ))); |
|
486 | + if (! empty($questions)) { |
|
487 | + // use fieldsets |
|
488 | + $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">'; |
|
489 | + // group_name |
|
490 | + if ($QSG->show_group_name()) { |
|
491 | + $html .= "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>'; |
|
492 | + } |
|
493 | + // group_desc |
|
494 | + if ($QSG->show_group_desc()) { |
|
495 | + $html .= '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>'; |
|
496 | + } |
|
497 | + |
|
498 | + $html .= $before_question_group_questions; |
|
499 | + // loop thru questions |
|
500 | + foreach ($questions as $QST) { |
|
501 | + $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID(); |
|
502 | + |
|
503 | + $answer = null; |
|
504 | + |
|
505 | + if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
506 | + // check for answer in $_GET in case we are reprocessing a form after an error |
|
507 | + if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) { |
|
508 | + $answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]); |
|
509 | + } |
|
510 | + } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
|
511 | + // attendee data from the session |
|
512 | + $answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + $QFI = new EE_Question_Form_Input( |
|
518 | + $QST, |
|
519 | + EE_Answer::new_instance(array( |
|
520 | + 'ANS_ID' => 0, |
|
521 | + 'QST_ID' => 0, |
|
522 | + 'REG_ID' => 0, |
|
523 | + 'ANS_value' => $answer |
|
524 | + )), |
|
525 | + $q_meta |
|
526 | + ); |
|
527 | + // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
528 | + $html .= self::generate_form_input($QFI); |
|
529 | + } |
|
530 | + $html .= $after_question_group_questions; |
|
531 | + $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
532 | + } |
|
533 | + } |
|
534 | + } |
|
535 | + } |
|
536 | + return $html; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * generate_form_input |
|
546 | + * |
|
547 | + * @param EE_Question_Form_Input $QFI |
|
548 | + * @return string HTML |
|
549 | + */ |
|
550 | + public static function generate_form_input(EE_Question_Form_Input $QFI) |
|
551 | + { |
|
552 | + if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) { |
|
553 | + return ''; |
|
554 | + } |
|
555 | + |
|
556 | + $QFI = self::_load_system_dropdowns($QFI); |
|
557 | + $QFI = self::_load_specialized_dropdowns($QFI); |
|
558 | + |
|
559 | + // we also need to verify |
|
560 | + |
|
561 | + $display_text = $QFI->get('QST_display_text'); |
|
562 | + $input_name = $QFI->get('QST_input_name'); |
|
563 | + $answer = EE_Registry::instance()->REQ->is_set($input_name) ? EE_Registry::instance()->REQ->get($input_name) : $QFI->get('ANS_value'); |
|
564 | + $input_id = $QFI->get('QST_input_id'); |
|
565 | + $input_class = $QFI->get('QST_input_class'); |
|
566 | 566 | // $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : ''; |
567 | - $disabled = $QFI->get('QST_disabled') ? true : false; |
|
568 | - $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>'); |
|
569 | - $QST_required = $QFI->get('QST_required'); |
|
570 | - $required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array(); |
|
571 | - $use_html_entities = $QFI->get_meta('htmlentities'); |
|
572 | - $required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso'); |
|
573 | - $required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : ''; |
|
574 | - $label_class = 'espresso-form-input-lbl'; |
|
575 | - $QST_options = $QFI->options(true, $answer); |
|
576 | - $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array(); |
|
577 | - $system_ID = $QFI->get('QST_system'); |
|
578 | - $label_b4 = $QFI->get_meta('label_b4'); |
|
579 | - $use_desc_4_label = $QFI->get_meta('use_desc_4_label'); |
|
580 | - |
|
581 | - |
|
582 | - switch ($QFI->get('QST_type')) { |
|
583 | - case 'TEXTAREA': |
|
584 | - return EEH_Form_Fields::textarea($display_text, $answer, $input_name, $input_id, $input_class, array(), $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
585 | - break; |
|
586 | - |
|
587 | - case 'DROPDOWN': |
|
588 | - return EEH_Form_Fields::select($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, true); |
|
589 | - break; |
|
590 | - |
|
591 | - |
|
592 | - case 'RADIO_BTN': |
|
593 | - return EEH_Form_Fields::radio($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, $label_b4, $use_desc_4_label); |
|
594 | - break; |
|
595 | - |
|
596 | - case 'CHECKBOX': |
|
597 | - return EEH_Form_Fields::checkbox($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $label_b4, $system_ID, $use_html_entities); |
|
598 | - break; |
|
599 | - |
|
600 | - case 'DATE': |
|
601 | - return EEH_Form_Fields::datepicker($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
602 | - break; |
|
603 | - |
|
604 | - case 'TEXT': |
|
605 | - default: |
|
606 | - return EEH_Form_Fields::text($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
607 | - break; |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * generates HTML for a form text input |
|
618 | - * |
|
619 | - * @param string $question label content |
|
620 | - * @param string $answer form input value attribute |
|
621 | - * @param string $name form input name attribute |
|
622 | - * @param string $id form input css id attribute |
|
623 | - * @param string $class form input css class attribute |
|
624 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
625 | - * @param string $label_class css class attribute for the label |
|
626 | - * @param string $disabled disabled="disabled" or null |
|
627 | - * @return string HTML |
|
628 | - */ |
|
629 | - public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
630 | - { |
|
631 | - // need these |
|
632 | - if (! $question || ! $name) { |
|
633 | - return null; |
|
634 | - } |
|
635 | - // prep the answer |
|
636 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
637 | - // prep the required array |
|
638 | - $required = self::prep_required($required); |
|
639 | - // set disabled tag |
|
640 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
641 | - // ya gots ta have style man!!! |
|
642 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
|
643 | - $class = empty($class) ? $txt_class : $class; |
|
644 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
645 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
646 | - |
|
647 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
648 | - // filter label but ensure required text comes before it |
|
649 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
650 | - |
|
651 | - $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
652 | - |
|
653 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
654 | - return $label_html . $input_html; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * generates HTML for a form textarea |
|
663 | - * |
|
664 | - * @param string $question label content |
|
665 | - * @param string $answer form input value attribute |
|
666 | - * @param string $name form input name attribute |
|
667 | - * @param string $id form input css id attribute |
|
668 | - * @param string $class form input css class attribute |
|
669 | - * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 ) |
|
670 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
671 | - * @param string $label_class css class attribute for the label |
|
672 | - * @param string $disabled disabled="disabled" or null |
|
673 | - * @return string HTML |
|
674 | - */ |
|
675 | - public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
676 | - { |
|
677 | - // need these |
|
678 | - if (! $question || ! $name) { |
|
679 | - return null; |
|
680 | - } |
|
681 | - // prep the answer |
|
682 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
683 | - // prep the required array |
|
684 | - $required = self::prep_required($required); |
|
685 | - // make sure $dimensions is an array |
|
686 | - $dimensions = is_array($dimensions) ? $dimensions : array(); |
|
687 | - // and set some defaults |
|
688 | - $dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions); |
|
689 | - // set disabled tag |
|
690 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
691 | - // ya gots ta have style man!!! |
|
692 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
|
693 | - $class = empty($class) ? $txt_class : $class; |
|
694 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
695 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
696 | - |
|
697 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
698 | - // filter label but ensure required text comes before it |
|
699 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
700 | - |
|
701 | - $input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>'; |
|
702 | - |
|
703 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
704 | - return $label_html . $input_html; |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * generates HTML for a form select input |
|
714 | - * |
|
715 | - * @param string $question label content |
|
716 | - * @param string $answer form input value attribute |
|
717 | - * @param array $options array of answer options where array key = option value and array value = option display text |
|
718 | - * @param string $name form input name attribute |
|
719 | - * @param string $id form input css id attribute |
|
720 | - * @param string $class form input css class attribute |
|
721 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
722 | - * @param string $label_class css class attribute for the label |
|
723 | - * @param string $disabled disabled="disabled" or null |
|
724 | - * @return string HTML |
|
725 | - */ |
|
726 | - public static function select($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $add_please_select_option = false) |
|
727 | - { |
|
728 | - |
|
729 | - // need these |
|
730 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
731 | - return null; |
|
732 | - } |
|
733 | - // prep the answer |
|
734 | - $answer = is_array($answer) ? self::prep_answer(array_shift($answer), $use_html_entities) : self::prep_answer($answer, $use_html_entities); |
|
735 | - // prep the required array |
|
736 | - $required = self::prep_required($required); |
|
737 | - // set disabled tag |
|
738 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
739 | - // ya gots ta have style man!!! |
|
740 | - $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
|
741 | - $class = empty($class) ? $txt_class : $class; |
|
742 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
743 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
744 | - |
|
745 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
746 | - // filter label but ensure required text comes before it |
|
747 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
748 | - |
|
749 | - $input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
750 | - // recursively count array elements, to determine total number of options |
|
751 | - $only_option = count($options, 1) == 1 ? true : false; |
|
752 | - if (! $only_option) { |
|
753 | - // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
|
754 | - $selected = $answer === null ? ' selected="selected"' : ''; |
|
755 | - $input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : ''; |
|
756 | - } |
|
757 | - foreach ($options as $key => $value) { |
|
758 | - // if value is an array, then create option groups, else create regular ol' options |
|
759 | - $input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities); |
|
760 | - } |
|
761 | - |
|
762 | - $input_html .= "\n\t\t\t" . '</select>'; |
|
763 | - |
|
764 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID); |
|
765 | - |
|
766 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
767 | - return $label_html . $input_html; |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - |
|
772 | - /** |
|
773 | - * _generate_select_option_group |
|
774 | - * |
|
775 | - * if $value for a select box is an array, then the key will be used as the optgroup label |
|
776 | - * and the value array will be looped thru and the elements sent to _generate_select_option |
|
777 | - * |
|
778 | - * @param mixed $opt_group |
|
779 | - * @param mixed $QSOs |
|
780 | - * @param mixed $answer |
|
781 | - * @param boolean $use_html_entities |
|
782 | - * @return string |
|
783 | - */ |
|
784 | - private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
|
785 | - { |
|
786 | - $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
787 | - foreach ($QSOs as $QSO) { |
|
788 | - $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
|
789 | - } |
|
790 | - $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
791 | - return $html; |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * _generate_select_option |
|
798 | - * @param mixed $key |
|
799 | - * @param mixed $value |
|
800 | - * @param mixed $answer |
|
801 | - * @param int $only_option |
|
802 | - * @param boolean $use_html_entities |
|
803 | - * @return string |
|
804 | - */ |
|
805 | - private static function _generate_select_option($key, $value, $answer, $only_option = false, $use_html_entities = true) |
|
806 | - { |
|
807 | - $key = self::prep_answer($key, $use_html_entities); |
|
808 | - $value = self::prep_answer($value, $use_html_entities); |
|
809 | - $value = ! empty($value) ? $value : $key; |
|
810 | - $selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : ''; |
|
811 | - return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . ' </option>'; |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * generates HTML for form radio button inputs |
|
818 | - * |
|
819 | - * @param bool|string $question label content |
|
820 | - * @param string $answer form input value attribute |
|
821 | - * @param array|bool $options array of answer options where array key = option value and array value = option display text |
|
822 | - * @param bool|string $name form input name attribute |
|
823 | - * @param string $id form input css id attribute |
|
824 | - * @param string $class form input css class attribute |
|
825 | - * @param array|bool $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
826 | - * @param string $required_text |
|
827 | - * @param string $label_class css class attribute for the label |
|
828 | - * @param bool|string $disabled disabled="disabled" or null |
|
829 | - * @param bool $system_ID |
|
830 | - * @param bool $use_html_entities |
|
831 | - * @param bool $label_b4 |
|
832 | - * @param bool $use_desc_4_label |
|
833 | - * @return string HTML |
|
834 | - */ |
|
835 | - public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false) |
|
836 | - { |
|
837 | - // need these |
|
838 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
839 | - return null; |
|
840 | - } |
|
841 | - // prep the answer |
|
842 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
843 | - // prep the required array |
|
844 | - $required = self::prep_required($required); |
|
845 | - // set disabled tag |
|
846 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
847 | - // ya gots ta have style man!!! |
|
848 | - $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
849 | - $class = ! empty($class) ? $class : 'espresso-radio-btn-inp'; |
|
850 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
851 | - |
|
852 | - $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
853 | - // filter label but ensure required text comes before it |
|
854 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
855 | - |
|
856 | - $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
857 | - |
|
858 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
859 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
860 | - |
|
861 | - foreach ($options as $OPT) { |
|
862 | - if ($OPT instanceof EE_Question_Option) { |
|
863 | - $value = self::prep_option_value($OPT->value()); |
|
864 | - $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
|
865 | - $size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value()); |
|
866 | - $desc = $OPT->desc();// no self::prep_answer |
|
867 | - $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
|
868 | - $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
|
869 | - $opt = '-' . sanitize_key($value); |
|
870 | - |
|
871 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
872 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
873 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
874 | - $input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
875 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : ''; |
|
876 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
877 | - $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
878 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
879 | - } |
|
880 | - } |
|
881 | - |
|
882 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
883 | - |
|
884 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
885 | - return $label_html . $input_html; |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - |
|
890 | - |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * generates HTML for form checkbox inputs |
|
895 | - * |
|
896 | - * @param string $question label content |
|
897 | - * @param string $answer form input value attribute |
|
898 | - * @param array $options array of options where array key = option value and array value = option display text |
|
899 | - * @param string $name form input name attribute |
|
900 | - * @param string $id form input css id attribute |
|
901 | - * @param string $class form input css class attribute |
|
902 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
903 | - * @param string $label_class css class attribute for the label |
|
904 | - * @param string $disabled disabled="disabled" or null |
|
905 | - * @return string HTML |
|
906 | - */ |
|
907 | - public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true) |
|
908 | - { |
|
909 | - // need these |
|
910 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
911 | - return null; |
|
912 | - } |
|
913 | - $answer = maybe_unserialize($answer); |
|
914 | - |
|
915 | - // prep the answer(s) |
|
916 | - $answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer ); |
|
917 | - |
|
918 | - foreach ($answer as $key => $value) { |
|
919 | - $key = self::prep_option_value($key); |
|
920 | - $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
921 | - } |
|
922 | - |
|
923 | - // prep the required array |
|
924 | - $required = self::prep_required($required); |
|
925 | - // set disabled tag |
|
926 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
927 | - // ya gots ta have style man!!! |
|
928 | - $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
929 | - $class = empty($class) ? 'espresso-radio-btn-inp' : $class; |
|
930 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
931 | - |
|
932 | - $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
933 | - // filter label but ensure required text comes before it |
|
934 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
935 | - |
|
936 | - $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
937 | - |
|
938 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
939 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
940 | - |
|
941 | - foreach ($options as $OPT) { |
|
942 | - $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
943 | - $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
944 | - $text = self::prep_answer($OPT->value()); |
|
945 | - $desc = $OPT->desc() ; |
|
946 | - $opt = '-' . sanitize_key($value); |
|
947 | - |
|
948 | - $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
|
949 | - |
|
950 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
951 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
952 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
953 | - $input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
954 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
955 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
956 | - if (! empty($desc) && $desc != $text) { |
|
957 | - $input_html .= "\n\t\t\t\t\t" . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>'; |
|
958 | - } |
|
959 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
960 | - } |
|
961 | - |
|
962 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
963 | - |
|
964 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
965 | - return $label_html . $input_html; |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - |
|
970 | - |
|
971 | - |
|
972 | - |
|
973 | - /** |
|
974 | - * generates HTML for a form datepicker input |
|
975 | - * |
|
976 | - * @param string $question label content |
|
977 | - * @param string $answer form input value attribute |
|
978 | - * @param string $name form input name attribute |
|
979 | - * @param string $id form input css id attribute |
|
980 | - * @param string $class form input css class attribute |
|
981 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
982 | - * @param string $label_class css class attribute for the label |
|
983 | - * @param string $disabled disabled="disabled" or null |
|
984 | - * @return string HTML |
|
985 | - */ |
|
986 | - public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
987 | - { |
|
988 | - // need these |
|
989 | - if (! $question || ! $name) { |
|
990 | - return null; |
|
991 | - } |
|
992 | - // prep the answer |
|
993 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
994 | - // prep the required array |
|
995 | - $required = self::prep_required($required); |
|
996 | - // set disabled tag |
|
997 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
998 | - // ya gots ta have style man!!! |
|
999 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
|
1000 | - $class = empty($class) ? $txt_class : $class; |
|
1001 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1002 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1003 | - |
|
1004 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
1005 | - // filter label but ensure required text comes before it |
|
1006 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1007 | - |
|
1008 | - $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1009 | - |
|
1010 | - // enqueue scripts |
|
1011 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
1012 | - wp_enqueue_style('espresso-ui-theme'); |
|
1013 | - wp_enqueue_script('jquery-ui-datepicker'); |
|
1014 | - |
|
1015 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1016 | - return $label_html . $input_html; |
|
1017 | - } |
|
1018 | - |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * remove_label_keep_required_msg |
|
1023 | - * this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label |
|
1024 | - * @access public |
|
1025 | - * @return string |
|
1026 | - */ |
|
1027 | - public static function remove_label_keep_required_msg($label_html, $required_text) |
|
1028 | - { |
|
1029 | - return $required_text; |
|
1030 | - } |
|
1031 | - |
|
1032 | - |
|
1033 | - |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * Simply return sthe HTML for a hidden input of the given name and value. |
|
1038 | - * @param string $name |
|
1039 | - * @param string $value |
|
1040 | - * @return string HTML |
|
1041 | - */ |
|
1042 | - public static function hidden_input($name, $value, $id = '') |
|
1043 | - { |
|
1044 | - $id = ! empty($id) ? $id : $name; |
|
1045 | - return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1046 | - } |
|
1047 | - |
|
1048 | - |
|
1049 | - |
|
1050 | - |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * prep_question |
|
1054 | - * @param string $question |
|
1055 | - * @return string |
|
1056 | - */ |
|
1057 | - public static function prep_question($question) |
|
1058 | - { |
|
1059 | - return $question; |
|
567 | + $disabled = $QFI->get('QST_disabled') ? true : false; |
|
568 | + $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>'); |
|
569 | + $QST_required = $QFI->get('QST_required'); |
|
570 | + $required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array(); |
|
571 | + $use_html_entities = $QFI->get_meta('htmlentities'); |
|
572 | + $required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso'); |
|
573 | + $required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : ''; |
|
574 | + $label_class = 'espresso-form-input-lbl'; |
|
575 | + $QST_options = $QFI->options(true, $answer); |
|
576 | + $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array(); |
|
577 | + $system_ID = $QFI->get('QST_system'); |
|
578 | + $label_b4 = $QFI->get_meta('label_b4'); |
|
579 | + $use_desc_4_label = $QFI->get_meta('use_desc_4_label'); |
|
580 | + |
|
581 | + |
|
582 | + switch ($QFI->get('QST_type')) { |
|
583 | + case 'TEXTAREA': |
|
584 | + return EEH_Form_Fields::textarea($display_text, $answer, $input_name, $input_id, $input_class, array(), $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
585 | + break; |
|
586 | + |
|
587 | + case 'DROPDOWN': |
|
588 | + return EEH_Form_Fields::select($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, true); |
|
589 | + break; |
|
590 | + |
|
591 | + |
|
592 | + case 'RADIO_BTN': |
|
593 | + return EEH_Form_Fields::radio($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities, $label_b4, $use_desc_4_label); |
|
594 | + break; |
|
595 | + |
|
596 | + case 'CHECKBOX': |
|
597 | + return EEH_Form_Fields::checkbox($display_text, $answer, $options, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $label_b4, $system_ID, $use_html_entities); |
|
598 | + break; |
|
599 | + |
|
600 | + case 'DATE': |
|
601 | + return EEH_Form_Fields::datepicker($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
602 | + break; |
|
603 | + |
|
604 | + case 'TEXT': |
|
605 | + default: |
|
606 | + return EEH_Form_Fields::text($display_text, $answer, $input_name, $input_id, $input_class, $required, $required_text, $label_class, $disabled, $system_ID, $use_html_entities); |
|
607 | + break; |
|
608 | + } |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * generates HTML for a form text input |
|
618 | + * |
|
619 | + * @param string $question label content |
|
620 | + * @param string $answer form input value attribute |
|
621 | + * @param string $name form input name attribute |
|
622 | + * @param string $id form input css id attribute |
|
623 | + * @param string $class form input css class attribute |
|
624 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
625 | + * @param string $label_class css class attribute for the label |
|
626 | + * @param string $disabled disabled="disabled" or null |
|
627 | + * @return string HTML |
|
628 | + */ |
|
629 | + public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
630 | + { |
|
631 | + // need these |
|
632 | + if (! $question || ! $name) { |
|
633 | + return null; |
|
634 | + } |
|
635 | + // prep the answer |
|
636 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
637 | + // prep the required array |
|
638 | + $required = self::prep_required($required); |
|
639 | + // set disabled tag |
|
640 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
641 | + // ya gots ta have style man!!! |
|
642 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
|
643 | + $class = empty($class) ? $txt_class : $class; |
|
644 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
645 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
646 | + |
|
647 | + $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
648 | + // filter label but ensure required text comes before it |
|
649 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
650 | + |
|
651 | + $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
652 | + |
|
653 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
654 | + return $label_html . $input_html; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * generates HTML for a form textarea |
|
663 | + * |
|
664 | + * @param string $question label content |
|
665 | + * @param string $answer form input value attribute |
|
666 | + * @param string $name form input name attribute |
|
667 | + * @param string $id form input css id attribute |
|
668 | + * @param string $class form input css class attribute |
|
669 | + * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 ) |
|
670 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
671 | + * @param string $label_class css class attribute for the label |
|
672 | + * @param string $disabled disabled="disabled" or null |
|
673 | + * @return string HTML |
|
674 | + */ |
|
675 | + public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
676 | + { |
|
677 | + // need these |
|
678 | + if (! $question || ! $name) { |
|
679 | + return null; |
|
680 | + } |
|
681 | + // prep the answer |
|
682 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
683 | + // prep the required array |
|
684 | + $required = self::prep_required($required); |
|
685 | + // make sure $dimensions is an array |
|
686 | + $dimensions = is_array($dimensions) ? $dimensions : array(); |
|
687 | + // and set some defaults |
|
688 | + $dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions); |
|
689 | + // set disabled tag |
|
690 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
691 | + // ya gots ta have style man!!! |
|
692 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
|
693 | + $class = empty($class) ? $txt_class : $class; |
|
694 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
695 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
696 | + |
|
697 | + $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
698 | + // filter label but ensure required text comes before it |
|
699 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
700 | + |
|
701 | + $input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>'; |
|
702 | + |
|
703 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
704 | + return $label_html . $input_html; |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * generates HTML for a form select input |
|
714 | + * |
|
715 | + * @param string $question label content |
|
716 | + * @param string $answer form input value attribute |
|
717 | + * @param array $options array of answer options where array key = option value and array value = option display text |
|
718 | + * @param string $name form input name attribute |
|
719 | + * @param string $id form input css id attribute |
|
720 | + * @param string $class form input css class attribute |
|
721 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
722 | + * @param string $label_class css class attribute for the label |
|
723 | + * @param string $disabled disabled="disabled" or null |
|
724 | + * @return string HTML |
|
725 | + */ |
|
726 | + public static function select($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $add_please_select_option = false) |
|
727 | + { |
|
728 | + |
|
729 | + // need these |
|
730 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
731 | + return null; |
|
732 | + } |
|
733 | + // prep the answer |
|
734 | + $answer = is_array($answer) ? self::prep_answer(array_shift($answer), $use_html_entities) : self::prep_answer($answer, $use_html_entities); |
|
735 | + // prep the required array |
|
736 | + $required = self::prep_required($required); |
|
737 | + // set disabled tag |
|
738 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
739 | + // ya gots ta have style man!!! |
|
740 | + $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
|
741 | + $class = empty($class) ? $txt_class : $class; |
|
742 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
743 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
744 | + |
|
745 | + $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
746 | + // filter label but ensure required text comes before it |
|
747 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
748 | + |
|
749 | + $input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
750 | + // recursively count array elements, to determine total number of options |
|
751 | + $only_option = count($options, 1) == 1 ? true : false; |
|
752 | + if (! $only_option) { |
|
753 | + // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
|
754 | + $selected = $answer === null ? ' selected="selected"' : ''; |
|
755 | + $input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : ''; |
|
756 | + } |
|
757 | + foreach ($options as $key => $value) { |
|
758 | + // if value is an array, then create option groups, else create regular ol' options |
|
759 | + $input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities); |
|
760 | + } |
|
761 | + |
|
762 | + $input_html .= "\n\t\t\t" . '</select>'; |
|
763 | + |
|
764 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID); |
|
765 | + |
|
766 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
767 | + return $label_html . $input_html; |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + |
|
772 | + /** |
|
773 | + * _generate_select_option_group |
|
774 | + * |
|
775 | + * if $value for a select box is an array, then the key will be used as the optgroup label |
|
776 | + * and the value array will be looped thru and the elements sent to _generate_select_option |
|
777 | + * |
|
778 | + * @param mixed $opt_group |
|
779 | + * @param mixed $QSOs |
|
780 | + * @param mixed $answer |
|
781 | + * @param boolean $use_html_entities |
|
782 | + * @return string |
|
783 | + */ |
|
784 | + private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
|
785 | + { |
|
786 | + $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
787 | + foreach ($QSOs as $QSO) { |
|
788 | + $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
|
789 | + } |
|
790 | + $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
791 | + return $html; |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * _generate_select_option |
|
798 | + * @param mixed $key |
|
799 | + * @param mixed $value |
|
800 | + * @param mixed $answer |
|
801 | + * @param int $only_option |
|
802 | + * @param boolean $use_html_entities |
|
803 | + * @return string |
|
804 | + */ |
|
805 | + private static function _generate_select_option($key, $value, $answer, $only_option = false, $use_html_entities = true) |
|
806 | + { |
|
807 | + $key = self::prep_answer($key, $use_html_entities); |
|
808 | + $value = self::prep_answer($value, $use_html_entities); |
|
809 | + $value = ! empty($value) ? $value : $key; |
|
810 | + $selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : ''; |
|
811 | + return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . ' </option>'; |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * generates HTML for form radio button inputs |
|
818 | + * |
|
819 | + * @param bool|string $question label content |
|
820 | + * @param string $answer form input value attribute |
|
821 | + * @param array|bool $options array of answer options where array key = option value and array value = option display text |
|
822 | + * @param bool|string $name form input name attribute |
|
823 | + * @param string $id form input css id attribute |
|
824 | + * @param string $class form input css class attribute |
|
825 | + * @param array|bool $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
826 | + * @param string $required_text |
|
827 | + * @param string $label_class css class attribute for the label |
|
828 | + * @param bool|string $disabled disabled="disabled" or null |
|
829 | + * @param bool $system_ID |
|
830 | + * @param bool $use_html_entities |
|
831 | + * @param bool $label_b4 |
|
832 | + * @param bool $use_desc_4_label |
|
833 | + * @return string HTML |
|
834 | + */ |
|
835 | + public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false) |
|
836 | + { |
|
837 | + // need these |
|
838 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
839 | + return null; |
|
840 | + } |
|
841 | + // prep the answer |
|
842 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
843 | + // prep the required array |
|
844 | + $required = self::prep_required($required); |
|
845 | + // set disabled tag |
|
846 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
847 | + // ya gots ta have style man!!! |
|
848 | + $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
849 | + $class = ! empty($class) ? $class : 'espresso-radio-btn-inp'; |
|
850 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
851 | + |
|
852 | + $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
853 | + // filter label but ensure required text comes before it |
|
854 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
855 | + |
|
856 | + $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
857 | + |
|
858 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
859 | + $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
860 | + |
|
861 | + foreach ($options as $OPT) { |
|
862 | + if ($OPT instanceof EE_Question_Option) { |
|
863 | + $value = self::prep_option_value($OPT->value()); |
|
864 | + $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
|
865 | + $size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value()); |
|
866 | + $desc = $OPT->desc();// no self::prep_answer |
|
867 | + $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
|
868 | + $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
|
869 | + $opt = '-' . sanitize_key($value); |
|
870 | + |
|
871 | + $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
872 | + $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
873 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
874 | + $input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
875 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : ''; |
|
876 | + $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
877 | + $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
878 | + $input_html .= "\n\t\t\t\t" . '</li>'; |
|
879 | + } |
|
880 | + } |
|
881 | + |
|
882 | + $input_html .= "\n\t\t\t" . '</ul>'; |
|
883 | + |
|
884 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
885 | + return $label_html . $input_html; |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + |
|
890 | + |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * generates HTML for form checkbox inputs |
|
895 | + * |
|
896 | + * @param string $question label content |
|
897 | + * @param string $answer form input value attribute |
|
898 | + * @param array $options array of options where array key = option value and array value = option display text |
|
899 | + * @param string $name form input name attribute |
|
900 | + * @param string $id form input css id attribute |
|
901 | + * @param string $class form input css class attribute |
|
902 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
903 | + * @param string $label_class css class attribute for the label |
|
904 | + * @param string $disabled disabled="disabled" or null |
|
905 | + * @return string HTML |
|
906 | + */ |
|
907 | + public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true) |
|
908 | + { |
|
909 | + // need these |
|
910 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
911 | + return null; |
|
912 | + } |
|
913 | + $answer = maybe_unserialize($answer); |
|
914 | + |
|
915 | + // prep the answer(s) |
|
916 | + $answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer ); |
|
917 | + |
|
918 | + foreach ($answer as $key => $value) { |
|
919 | + $key = self::prep_option_value($key); |
|
920 | + $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
921 | + } |
|
922 | + |
|
923 | + // prep the required array |
|
924 | + $required = self::prep_required($required); |
|
925 | + // set disabled tag |
|
926 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
927 | + // ya gots ta have style man!!! |
|
928 | + $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
929 | + $class = empty($class) ? 'espresso-radio-btn-inp' : $class; |
|
930 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
931 | + |
|
932 | + $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
933 | + // filter label but ensure required text comes before it |
|
934 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
935 | + |
|
936 | + $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
937 | + |
|
938 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
939 | + $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
940 | + |
|
941 | + foreach ($options as $OPT) { |
|
942 | + $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
943 | + $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
944 | + $text = self::prep_answer($OPT->value()); |
|
945 | + $desc = $OPT->desc() ; |
|
946 | + $opt = '-' . sanitize_key($value); |
|
947 | + |
|
948 | + $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
|
949 | + |
|
950 | + $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
951 | + $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
952 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
953 | + $input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
954 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
955 | + $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
956 | + if (! empty($desc) && $desc != $text) { |
|
957 | + $input_html .= "\n\t\t\t\t\t" . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>'; |
|
958 | + } |
|
959 | + $input_html .= "\n\t\t\t\t" . '</li>'; |
|
960 | + } |
|
961 | + |
|
962 | + $input_html .= "\n\t\t\t" . '</ul>'; |
|
963 | + |
|
964 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
965 | + return $label_html . $input_html; |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + |
|
970 | + |
|
971 | + |
|
972 | + |
|
973 | + /** |
|
974 | + * generates HTML for a form datepicker input |
|
975 | + * |
|
976 | + * @param string $question label content |
|
977 | + * @param string $answer form input value attribute |
|
978 | + * @param string $name form input name attribute |
|
979 | + * @param string $id form input css id attribute |
|
980 | + * @param string $class form input css class attribute |
|
981 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css required 'class', and required 'msg' attribute |
|
982 | + * @param string $label_class css class attribute for the label |
|
983 | + * @param string $disabled disabled="disabled" or null |
|
984 | + * @return string HTML |
|
985 | + */ |
|
986 | + public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
|
987 | + { |
|
988 | + // need these |
|
989 | + if (! $question || ! $name) { |
|
990 | + return null; |
|
991 | + } |
|
992 | + // prep the answer |
|
993 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
994 | + // prep the required array |
|
995 | + $required = self::prep_required($required); |
|
996 | + // set disabled tag |
|
997 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
998 | + // ya gots ta have style man!!! |
|
999 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
|
1000 | + $class = empty($class) ? $txt_class : $class; |
|
1001 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1002 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1003 | + |
|
1004 | + $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
1005 | + // filter label but ensure required text comes before it |
|
1006 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1007 | + |
|
1008 | + $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1009 | + |
|
1010 | + // enqueue scripts |
|
1011 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
1012 | + wp_enqueue_style('espresso-ui-theme'); |
|
1013 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
1014 | + |
|
1015 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1016 | + return $label_html . $input_html; |
|
1017 | + } |
|
1018 | + |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * remove_label_keep_required_msg |
|
1023 | + * this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label |
|
1024 | + * @access public |
|
1025 | + * @return string |
|
1026 | + */ |
|
1027 | + public static function remove_label_keep_required_msg($label_html, $required_text) |
|
1028 | + { |
|
1029 | + return $required_text; |
|
1030 | + } |
|
1031 | + |
|
1032 | + |
|
1033 | + |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * Simply return sthe HTML for a hidden input of the given name and value. |
|
1038 | + * @param string $name |
|
1039 | + * @param string $value |
|
1040 | + * @return string HTML |
|
1041 | + */ |
|
1042 | + public static function hidden_input($name, $value, $id = '') |
|
1043 | + { |
|
1044 | + $id = ! empty($id) ? $id : $name; |
|
1045 | + return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1046 | + } |
|
1047 | + |
|
1048 | + |
|
1049 | + |
|
1050 | + |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * prep_question |
|
1054 | + * @param string $question |
|
1055 | + * @return string |
|
1056 | + */ |
|
1057 | + public static function prep_question($question) |
|
1058 | + { |
|
1059 | + return $question; |
|
1060 | 1060 | // $link = ''; |
1061 | 1061 | // // does this label have a help link attached ? |
1062 | 1062 | // if ( strpos( $question, '<a ' ) !== FALSE ) { |
@@ -1068,447 +1068,447 @@ discard block |
||
1068 | 1068 | // $link = '<a ' . $link; |
1069 | 1069 | // } |
1070 | 1070 | // return htmlspecialchars( trim( stripslashes( str_replace( ''', "'", $question ))), ENT_QUOTES, 'UTF-8' ) . ' ' . $link; |
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * prep_answer |
|
1078 | - * @param mixed $answer |
|
1079 | - * @return string |
|
1080 | - */ |
|
1081 | - public static function prep_answer($answer, $use_html_entities = true) |
|
1082 | - { |
|
1083 | - // make sure we convert bools first. Otherwise (bool) false becomes an empty string which is NOT desired, we want "0". |
|
1084 | - if (is_bool($answer)) { |
|
1085 | - $answer = $answer ? 1 : 0; |
|
1086 | - } |
|
1087 | - $answer = trim(stripslashes(str_replace(''', "'", $answer))); |
|
1088 | - return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer; |
|
1089 | - } |
|
1090 | - |
|
1091 | - |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * prep_answer_options |
|
1095 | - * @param array $QSOs array of EE_Question_Option objects |
|
1096 | - * @return array |
|
1097 | - */ |
|
1098 | - public static function prep_answer_options($QSOs = array()) |
|
1099 | - { |
|
1100 | - $prepped_answer_options = array(); |
|
1101 | - if (is_array($QSOs) && ! empty($QSOs)) { |
|
1102 | - foreach ($QSOs as $key => $QSO) { |
|
1103 | - if (! $QSO instanceof EE_Question_Option) { |
|
1104 | - $QSO = EE_Question_Option::new_instance(array( |
|
1105 | - 'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key, |
|
1106 | - 'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO |
|
1107 | - )); |
|
1108 | - } |
|
1109 | - if ($QSO->opt_group()) { |
|
1110 | - $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1111 | - } else { |
|
1112 | - $prepped_answer_options[] = $QSO; |
|
1113 | - } |
|
1114 | - } |
|
1115 | - } |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * prep_answer |
|
1078 | + * @param mixed $answer |
|
1079 | + * @return string |
|
1080 | + */ |
|
1081 | + public static function prep_answer($answer, $use_html_entities = true) |
|
1082 | + { |
|
1083 | + // make sure we convert bools first. Otherwise (bool) false becomes an empty string which is NOT desired, we want "0". |
|
1084 | + if (is_bool($answer)) { |
|
1085 | + $answer = $answer ? 1 : 0; |
|
1086 | + } |
|
1087 | + $answer = trim(stripslashes(str_replace(''', "'", $answer))); |
|
1088 | + return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer; |
|
1089 | + } |
|
1090 | + |
|
1091 | + |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * prep_answer_options |
|
1095 | + * @param array $QSOs array of EE_Question_Option objects |
|
1096 | + * @return array |
|
1097 | + */ |
|
1098 | + public static function prep_answer_options($QSOs = array()) |
|
1099 | + { |
|
1100 | + $prepped_answer_options = array(); |
|
1101 | + if (is_array($QSOs) && ! empty($QSOs)) { |
|
1102 | + foreach ($QSOs as $key => $QSO) { |
|
1103 | + if (! $QSO instanceof EE_Question_Option) { |
|
1104 | + $QSO = EE_Question_Option::new_instance(array( |
|
1105 | + 'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key, |
|
1106 | + 'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO |
|
1107 | + )); |
|
1108 | + } |
|
1109 | + if ($QSO->opt_group()) { |
|
1110 | + $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1111 | + } else { |
|
1112 | + $prepped_answer_options[] = $QSO; |
|
1113 | + } |
|
1114 | + } |
|
1115 | + } |
|
1116 | 1116 | // d( $prepped_answer_options ); |
1117 | - return $prepped_answer_options; |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * prep_option_value |
|
1123 | - * @param string $option_value |
|
1124 | - * @return string |
|
1125 | - */ |
|
1126 | - public static function prep_option_value($option_value) |
|
1127 | - { |
|
1128 | - return esc_attr(trim(stripslashes($option_value))); |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * prep_required |
|
1136 | - * @param string|array $required |
|
1137 | - * @return array |
|
1138 | - */ |
|
1139 | - public static function prep_required($required = array()) |
|
1140 | - { |
|
1141 | - // make sure required is an array |
|
1142 | - $required = is_array($required) ? $required : array(); |
|
1143 | - // and set some defaults |
|
1144 | - $required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required); |
|
1145 | - return $required; |
|
1146 | - } |
|
1147 | - |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * get_label_size_class |
|
1152 | - * @param string $value |
|
1153 | - * @return string |
|
1154 | - */ |
|
1155 | - public static function get_label_size_class($value = false) |
|
1156 | - { |
|
1157 | - if ($value === false || $value == '') { |
|
1158 | - return ' class="medium-lbl"'; |
|
1159 | - } |
|
1160 | - // determine length of option value |
|
1161 | - $val_size = strlen($value); |
|
1162 | - switch ($val_size) { |
|
1163 | - case $val_size < 3: |
|
1164 | - $size = ' class="nano-lbl"'; |
|
1165 | - break; |
|
1166 | - case $val_size < 6: |
|
1167 | - $size = ' class="micro-lbl"'; |
|
1168 | - break; |
|
1169 | - case $val_size < 12: |
|
1170 | - $size = ' class="tiny-lbl"'; |
|
1171 | - break; |
|
1172 | - case $val_size < 25: |
|
1173 | - $size = ' class="small-lbl"'; |
|
1174 | - break; |
|
1175 | - case $val_size > 100: |
|
1176 | - $size = ' class="big-lbl"'; |
|
1177 | - break; |
|
1178 | - default: |
|
1179 | - $size = ' class="medium-lbl"'; |
|
1180 | - break; |
|
1181 | - } |
|
1182 | - return $size; |
|
1183 | - } |
|
1184 | - |
|
1185 | - |
|
1186 | - |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * _load_system_dropdowns |
|
1190 | - * @param array $QFI |
|
1191 | - * @return array |
|
1192 | - */ |
|
1193 | - private static function _load_system_dropdowns($QFI) |
|
1194 | - { |
|
1195 | - $QST_system = $QFI->get('QST_system'); |
|
1196 | - switch ($QST_system) { |
|
1197 | - case 'state': |
|
1198 | - $QFI = self::generate_state_dropdown($QFI); |
|
1199 | - break; |
|
1200 | - case 'country': |
|
1201 | - $QFI = self::generate_country_dropdown($QFI); |
|
1202 | - break; |
|
1203 | - case 'admin-state': |
|
1204 | - $QFI = self::generate_state_dropdown($QFI, true); |
|
1205 | - break; |
|
1206 | - case 'admin-country': |
|
1207 | - $QFI = self::generate_country_dropdown($QFI, true); |
|
1208 | - break; |
|
1209 | - } |
|
1210 | - return $QFI; |
|
1211 | - } |
|
1212 | - |
|
1213 | - |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * This preps dropdowns that are specialized. |
|
1217 | - * |
|
1218 | - * @since 4.6.0 |
|
1219 | - * |
|
1220 | - * @param EE_Question_Form_Input $QFI |
|
1221 | - * |
|
1222 | - * @return EE_Question_Form_Input |
|
1223 | - */ |
|
1224 | - protected static function _load_specialized_dropdowns($QFI) |
|
1225 | - { |
|
1226 | - switch ($QFI->get('QST_type')) { |
|
1227 | - case 'STATE': |
|
1228 | - $QFI = self::generate_state_dropdown($QFI); |
|
1229 | - break; |
|
1230 | - case 'COUNTRY': |
|
1231 | - $QFI = self::generate_country_dropdown($QFI); |
|
1232 | - break; |
|
1233 | - } |
|
1234 | - return $QFI; |
|
1235 | - } |
|
1236 | - |
|
1237 | - |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * generate_state_dropdown |
|
1241 | - * @param array $QST |
|
1242 | - * @param bool $get_all |
|
1243 | - * @return array |
|
1244 | - */ |
|
1245 | - public static function generate_state_dropdown($QST, $get_all = false) |
|
1246 | - { |
|
1247 | - $states = $get_all ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_states_of_active_countries(); |
|
1248 | - if ($states && count($states) != count($QST->options())) { |
|
1249 | - $QST->set('QST_type', 'DROPDOWN'); |
|
1250 | - // if multiple countries, we'll create option groups within the dropdown |
|
1251 | - foreach ($states as $state) { |
|
1252 | - if ($state instanceof EE_State) { |
|
1253 | - $QSO = EE_Question_Option::new_instance(array ( |
|
1254 | - 'QSO_value' => $state->ID(), |
|
1255 | - 'QSO_desc' => $state->name(), |
|
1256 | - 'QST_ID' => $QST->get('QST_ID'), |
|
1257 | - 'QSO_deleted' => false |
|
1258 | - )); |
|
1259 | - // set option group |
|
1260 | - $QSO->set_opt_group($state->country()->name()); |
|
1261 | - // add option to question |
|
1262 | - $QST->add_temp_option($QSO); |
|
1263 | - } |
|
1264 | - } |
|
1265 | - } |
|
1266 | - return $QST; |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * generate_country_dropdown |
|
1273 | - * @param $QST |
|
1274 | - * @param bool $get_all |
|
1275 | - * @internal param array $question |
|
1276 | - * @return array |
|
1277 | - */ |
|
1278 | - public static function generate_country_dropdown($QST, $get_all = false) |
|
1279 | - { |
|
1280 | - $countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries(); |
|
1281 | - if ($countries && count($countries) != count($QST->options())) { |
|
1282 | - $QST->set('QST_type', 'DROPDOWN'); |
|
1283 | - // now add countries |
|
1284 | - foreach ($countries as $country) { |
|
1285 | - if ($country instanceof EE_Country) { |
|
1286 | - $QSO = EE_Question_Option::new_instance(array ( |
|
1287 | - 'QSO_value' => $country->ID(), |
|
1288 | - 'QSO_desc' => $country->name(), |
|
1289 | - 'QST_ID' => $QST->get('QST_ID'), |
|
1290 | - 'QSO_deleted' => false |
|
1291 | - )); |
|
1292 | - $QST->add_temp_option($QSO); |
|
1293 | - } |
|
1294 | - } |
|
1295 | - } |
|
1296 | - return $QST; |
|
1297 | - } |
|
1298 | - |
|
1299 | - |
|
1300 | - |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * generates options for a month dropdown selector with numbers from 01 to 12 |
|
1305 | - * @return array() |
|
1306 | - */ |
|
1307 | - public static function two_digit_months_dropdown_options() |
|
1308 | - { |
|
1309 | - $options = array(); |
|
1310 | - for ($x = 1; $x <= 12; $x++) { |
|
1311 | - $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1312 | - $options[ (string) $mm ] = (string) $mm; |
|
1313 | - } |
|
1314 | - return EEH_Form_Fields::prep_answer_options($options); |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * generates a year dropdown selector with numbers for the next ten years |
|
1323 | - * @return object |
|
1324 | - */ |
|
1325 | - public static function next_decade_two_digit_year_dropdown_options() |
|
1326 | - { |
|
1327 | - $options = array(); |
|
1328 | - $current_year = date('y'); |
|
1329 | - $next_decade = $current_year + 10; |
|
1330 | - for ($x = $current_year; $x <= $next_decade; $x++) { |
|
1331 | - $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1332 | - $options[ (string) $yy ] = (string) $yy; |
|
1333 | - } |
|
1334 | - return EEH_Form_Fields::prep_answer_options($options); |
|
1335 | - } |
|
1336 | - |
|
1337 | - |
|
1338 | - |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * generates a month/year dropdown selector for all registrations matching the given criteria. Typically used for list table filter. |
|
1343 | - * @param string $cur_date any currently selected date can be entered here. |
|
1344 | - * @param string $status Registration status |
|
1345 | - * @param integer $evt_category Event Category ID if the Event Category filter is selected |
|
1346 | - * @return string html |
|
1347 | - */ |
|
1348 | - public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
|
1349 | - { |
|
1350 | - $_where = array(); |
|
1351 | - if (!empty($status)) { |
|
1352 | - $_where['STS_ID'] = $status; |
|
1353 | - } |
|
1354 | - |
|
1355 | - if ($evt_category > 0) { |
|
1356 | - $_where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1357 | - } |
|
1358 | - |
|
1359 | - $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where); |
|
1360 | - |
|
1361 | - // setup vals for select input helper |
|
1362 | - $options = array( |
|
1363 | - 0 => array( |
|
1364 | - 'text' => __('Select a Month/Year', 'event_espresso'), |
|
1365 | - 'id' => '' |
|
1366 | - ) |
|
1367 | - ); |
|
1368 | - |
|
1369 | - foreach ($regdtts as $regdtt) { |
|
1370 | - $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1371 | - $options[] = array( |
|
1372 | - 'text' => $date, |
|
1373 | - 'id' => $date |
|
1374 | - ); |
|
1375 | - } |
|
1376 | - |
|
1377 | - return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - |
|
1382 | - /** |
|
1383 | - * generates a month/year dropdown selector for all events matching the given criteria |
|
1384 | - * Typically used for list table filter |
|
1385 | - * @param string $cur_date any currently selected date can be entered here. |
|
1386 | - * @param string $status "view" (i.e. all, today, month, draft) |
|
1387 | - * @param int $evt_category category event belongs to |
|
1388 | - * @param string $evt_active_status "upcoming", "expired", "active", or "inactive" |
|
1389 | - * @return string html |
|
1390 | - */ |
|
1391 | - public static function generate_event_months_dropdown($cur_date = '', $status = null, $evt_category = null, $evt_active_status = null) |
|
1392 | - { |
|
1393 | - // determine what post_status our condition will have for the query. |
|
1394 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
1395 | - switch ($status) { |
|
1396 | - case 'month': |
|
1397 | - case 'today': |
|
1398 | - case null: |
|
1399 | - case 'all': |
|
1400 | - $where['Event.status'] = array( 'NOT IN', array('trash') ); |
|
1401 | - break; |
|
1402 | - |
|
1403 | - case 'draft': |
|
1404 | - $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') ); |
|
1405 | - |
|
1406 | - default: |
|
1407 | - $where['Event.status'] = $status; |
|
1408 | - } |
|
1409 | - |
|
1410 | - // phpcs:enable |
|
1411 | - |
|
1412 | - // categories? |
|
1413 | - |
|
1117 | + return $prepped_answer_options; |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * prep_option_value |
|
1123 | + * @param string $option_value |
|
1124 | + * @return string |
|
1125 | + */ |
|
1126 | + public static function prep_option_value($option_value) |
|
1127 | + { |
|
1128 | + return esc_attr(trim(stripslashes($option_value))); |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * prep_required |
|
1136 | + * @param string|array $required |
|
1137 | + * @return array |
|
1138 | + */ |
|
1139 | + public static function prep_required($required = array()) |
|
1140 | + { |
|
1141 | + // make sure required is an array |
|
1142 | + $required = is_array($required) ? $required : array(); |
|
1143 | + // and set some defaults |
|
1144 | + $required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required); |
|
1145 | + return $required; |
|
1146 | + } |
|
1147 | + |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * get_label_size_class |
|
1152 | + * @param string $value |
|
1153 | + * @return string |
|
1154 | + */ |
|
1155 | + public static function get_label_size_class($value = false) |
|
1156 | + { |
|
1157 | + if ($value === false || $value == '') { |
|
1158 | + return ' class="medium-lbl"'; |
|
1159 | + } |
|
1160 | + // determine length of option value |
|
1161 | + $val_size = strlen($value); |
|
1162 | + switch ($val_size) { |
|
1163 | + case $val_size < 3: |
|
1164 | + $size = ' class="nano-lbl"'; |
|
1165 | + break; |
|
1166 | + case $val_size < 6: |
|
1167 | + $size = ' class="micro-lbl"'; |
|
1168 | + break; |
|
1169 | + case $val_size < 12: |
|
1170 | + $size = ' class="tiny-lbl"'; |
|
1171 | + break; |
|
1172 | + case $val_size < 25: |
|
1173 | + $size = ' class="small-lbl"'; |
|
1174 | + break; |
|
1175 | + case $val_size > 100: |
|
1176 | + $size = ' class="big-lbl"'; |
|
1177 | + break; |
|
1178 | + default: |
|
1179 | + $size = ' class="medium-lbl"'; |
|
1180 | + break; |
|
1181 | + } |
|
1182 | + return $size; |
|
1183 | + } |
|
1184 | + |
|
1185 | + |
|
1186 | + |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * _load_system_dropdowns |
|
1190 | + * @param array $QFI |
|
1191 | + * @return array |
|
1192 | + */ |
|
1193 | + private static function _load_system_dropdowns($QFI) |
|
1194 | + { |
|
1195 | + $QST_system = $QFI->get('QST_system'); |
|
1196 | + switch ($QST_system) { |
|
1197 | + case 'state': |
|
1198 | + $QFI = self::generate_state_dropdown($QFI); |
|
1199 | + break; |
|
1200 | + case 'country': |
|
1201 | + $QFI = self::generate_country_dropdown($QFI); |
|
1202 | + break; |
|
1203 | + case 'admin-state': |
|
1204 | + $QFI = self::generate_state_dropdown($QFI, true); |
|
1205 | + break; |
|
1206 | + case 'admin-country': |
|
1207 | + $QFI = self::generate_country_dropdown($QFI, true); |
|
1208 | + break; |
|
1209 | + } |
|
1210 | + return $QFI; |
|
1211 | + } |
|
1212 | + |
|
1213 | + |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * This preps dropdowns that are specialized. |
|
1217 | + * |
|
1218 | + * @since 4.6.0 |
|
1219 | + * |
|
1220 | + * @param EE_Question_Form_Input $QFI |
|
1221 | + * |
|
1222 | + * @return EE_Question_Form_Input |
|
1223 | + */ |
|
1224 | + protected static function _load_specialized_dropdowns($QFI) |
|
1225 | + { |
|
1226 | + switch ($QFI->get('QST_type')) { |
|
1227 | + case 'STATE': |
|
1228 | + $QFI = self::generate_state_dropdown($QFI); |
|
1229 | + break; |
|
1230 | + case 'COUNTRY': |
|
1231 | + $QFI = self::generate_country_dropdown($QFI); |
|
1232 | + break; |
|
1233 | + } |
|
1234 | + return $QFI; |
|
1235 | + } |
|
1236 | + |
|
1237 | + |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * generate_state_dropdown |
|
1241 | + * @param array $QST |
|
1242 | + * @param bool $get_all |
|
1243 | + * @return array |
|
1244 | + */ |
|
1245 | + public static function generate_state_dropdown($QST, $get_all = false) |
|
1246 | + { |
|
1247 | + $states = $get_all ? EEM_State::instance()->get_all_states() : EEM_State::instance()->get_all_states_of_active_countries(); |
|
1248 | + if ($states && count($states) != count($QST->options())) { |
|
1249 | + $QST->set('QST_type', 'DROPDOWN'); |
|
1250 | + // if multiple countries, we'll create option groups within the dropdown |
|
1251 | + foreach ($states as $state) { |
|
1252 | + if ($state instanceof EE_State) { |
|
1253 | + $QSO = EE_Question_Option::new_instance(array ( |
|
1254 | + 'QSO_value' => $state->ID(), |
|
1255 | + 'QSO_desc' => $state->name(), |
|
1256 | + 'QST_ID' => $QST->get('QST_ID'), |
|
1257 | + 'QSO_deleted' => false |
|
1258 | + )); |
|
1259 | + // set option group |
|
1260 | + $QSO->set_opt_group($state->country()->name()); |
|
1261 | + // add option to question |
|
1262 | + $QST->add_temp_option($QSO); |
|
1263 | + } |
|
1264 | + } |
|
1265 | + } |
|
1266 | + return $QST; |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * generate_country_dropdown |
|
1273 | + * @param $QST |
|
1274 | + * @param bool $get_all |
|
1275 | + * @internal param array $question |
|
1276 | + * @return array |
|
1277 | + */ |
|
1278 | + public static function generate_country_dropdown($QST, $get_all = false) |
|
1279 | + { |
|
1280 | + $countries = $get_all ? EEM_Country::instance()->get_all_countries() : EEM_Country::instance()->get_all_active_countries(); |
|
1281 | + if ($countries && count($countries) != count($QST->options())) { |
|
1282 | + $QST->set('QST_type', 'DROPDOWN'); |
|
1283 | + // now add countries |
|
1284 | + foreach ($countries as $country) { |
|
1285 | + if ($country instanceof EE_Country) { |
|
1286 | + $QSO = EE_Question_Option::new_instance(array ( |
|
1287 | + 'QSO_value' => $country->ID(), |
|
1288 | + 'QSO_desc' => $country->name(), |
|
1289 | + 'QST_ID' => $QST->get('QST_ID'), |
|
1290 | + 'QSO_deleted' => false |
|
1291 | + )); |
|
1292 | + $QST->add_temp_option($QSO); |
|
1293 | + } |
|
1294 | + } |
|
1295 | + } |
|
1296 | + return $QST; |
|
1297 | + } |
|
1298 | + |
|
1299 | + |
|
1300 | + |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * generates options for a month dropdown selector with numbers from 01 to 12 |
|
1305 | + * @return array() |
|
1306 | + */ |
|
1307 | + public static function two_digit_months_dropdown_options() |
|
1308 | + { |
|
1309 | + $options = array(); |
|
1310 | + for ($x = 1; $x <= 12; $x++) { |
|
1311 | + $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1312 | + $options[ (string) $mm ] = (string) $mm; |
|
1313 | + } |
|
1314 | + return EEH_Form_Fields::prep_answer_options($options); |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * generates a year dropdown selector with numbers for the next ten years |
|
1323 | + * @return object |
|
1324 | + */ |
|
1325 | + public static function next_decade_two_digit_year_dropdown_options() |
|
1326 | + { |
|
1327 | + $options = array(); |
|
1328 | + $current_year = date('y'); |
|
1329 | + $next_decade = $current_year + 10; |
|
1330 | + for ($x = $current_year; $x <= $next_decade; $x++) { |
|
1331 | + $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1332 | + $options[ (string) $yy ] = (string) $yy; |
|
1333 | + } |
|
1334 | + return EEH_Form_Fields::prep_answer_options($options); |
|
1335 | + } |
|
1336 | + |
|
1337 | + |
|
1338 | + |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * generates a month/year dropdown selector for all registrations matching the given criteria. Typically used for list table filter. |
|
1343 | + * @param string $cur_date any currently selected date can be entered here. |
|
1344 | + * @param string $status Registration status |
|
1345 | + * @param integer $evt_category Event Category ID if the Event Category filter is selected |
|
1346 | + * @return string html |
|
1347 | + */ |
|
1348 | + public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
|
1349 | + { |
|
1350 | + $_where = array(); |
|
1351 | + if (!empty($status)) { |
|
1352 | + $_where['STS_ID'] = $status; |
|
1353 | + } |
|
1354 | + |
|
1355 | + if ($evt_category > 0) { |
|
1356 | + $_where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1357 | + } |
|
1358 | + |
|
1359 | + $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where); |
|
1360 | + |
|
1361 | + // setup vals for select input helper |
|
1362 | + $options = array( |
|
1363 | + 0 => array( |
|
1364 | + 'text' => __('Select a Month/Year', 'event_espresso'), |
|
1365 | + 'id' => '' |
|
1366 | + ) |
|
1367 | + ); |
|
1368 | + |
|
1369 | + foreach ($regdtts as $regdtt) { |
|
1370 | + $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1371 | + $options[] = array( |
|
1372 | + 'text' => $date, |
|
1373 | + 'id' => $date |
|
1374 | + ); |
|
1375 | + } |
|
1376 | + |
|
1377 | + return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + |
|
1382 | + /** |
|
1383 | + * generates a month/year dropdown selector for all events matching the given criteria |
|
1384 | + * Typically used for list table filter |
|
1385 | + * @param string $cur_date any currently selected date can be entered here. |
|
1386 | + * @param string $status "view" (i.e. all, today, month, draft) |
|
1387 | + * @param int $evt_category category event belongs to |
|
1388 | + * @param string $evt_active_status "upcoming", "expired", "active", or "inactive" |
|
1389 | + * @return string html |
|
1390 | + */ |
|
1391 | + public static function generate_event_months_dropdown($cur_date = '', $status = null, $evt_category = null, $evt_active_status = null) |
|
1392 | + { |
|
1393 | + // determine what post_status our condition will have for the query. |
|
1394 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
1395 | + switch ($status) { |
|
1396 | + case 'month': |
|
1397 | + case 'today': |
|
1398 | + case null: |
|
1399 | + case 'all': |
|
1400 | + $where['Event.status'] = array( 'NOT IN', array('trash') ); |
|
1401 | + break; |
|
1402 | + |
|
1403 | + case 'draft': |
|
1404 | + $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') ); |
|
1405 | + |
|
1406 | + default: |
|
1407 | + $where['Event.status'] = $status; |
|
1408 | + } |
|
1409 | + |
|
1410 | + // phpcs:enable |
|
1411 | + |
|
1412 | + // categories? |
|
1413 | + |
|
1414 | 1414 | |
1415 | - if (!empty($evt_category)) { |
|
1416 | - $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1417 | - $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1418 | - } |
|
1415 | + if (!empty($evt_category)) { |
|
1416 | + $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1417 | + $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1418 | + } |
|
1419 | 1419 | |
1420 | 1420 | |
1421 | 1421 | // $where['DTT_is_primary'] = 1; |
1422 | 1422 | |
1423 | - $DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status); |
|
1424 | - |
|
1425 | - // let's setup vals for select input helper |
|
1426 | - $options = array( |
|
1427 | - 0 => array( |
|
1428 | - 'text' => __('Select a Month/Year', 'event_espresso'), |
|
1429 | - 'id' => "" |
|
1430 | - ) |
|
1431 | - ); |
|
1432 | - |
|
1433 | - |
|
1434 | - |
|
1435 | - // translate month and date |
|
1436 | - global $wp_locale; |
|
1437 | - |
|
1438 | - foreach ($DTTS as $DTT) { |
|
1439 | - $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1440 | - $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1441 | - $options[] = array( |
|
1442 | - 'text' => $localized_date, |
|
1443 | - 'id' => $id |
|
1444 | - ); |
|
1445 | - } |
|
1446 | - |
|
1447 | - |
|
1448 | - return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1449 | - } |
|
1450 | - |
|
1451 | - |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * generates the dropdown selector for event categories |
|
1455 | - * typically used as a filter on list tables. |
|
1456 | - * @param integer $current_cat currently selected category |
|
1457 | - * @return string html for dropdown |
|
1458 | - */ |
|
1459 | - public static function generate_event_category_dropdown($current_cat = -1) |
|
1460 | - { |
|
1461 | - $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
1462 | - $options = array( |
|
1463 | - '0' => array( |
|
1464 | - 'text' => __('All Categories', 'event_espresso'), |
|
1465 | - 'id' => -1 |
|
1466 | - ) |
|
1467 | - ); |
|
1468 | - |
|
1469 | - // setup categories for dropdown |
|
1470 | - foreach ($categories as $category) { |
|
1471 | - $options[] = array( |
|
1472 | - 'text' => $category->get('name'), |
|
1473 | - 'id' => $category->ID() |
|
1474 | - ); |
|
1475 | - } |
|
1476 | - |
|
1477 | - return self::select_input('EVT_CAT', $options, $current_cat); |
|
1478 | - } |
|
1479 | - |
|
1480 | - |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * generate a submit button with or without it's own microform |
|
1484 | - * this is the only way to create buttons that are compatible across all themes |
|
1485 | - * |
|
1486 | - * @access public |
|
1487 | - * @param string $url - the form action |
|
1488 | - * @param string $ID - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form |
|
1489 | - * @param string $class - css classes (separated by spaces if more than one) |
|
1490 | - * @param string $text - what appears on the button |
|
1491 | - * @param string $nonce_action - if using nonces |
|
1492 | - * @param bool|string $input_only - whether to print form header and footer. TRUE returns the input without the form |
|
1493 | - * @param string $extra_attributes - any extra attributes that need to be attached to the form input |
|
1494 | - * @return void |
|
1495 | - */ |
|
1496 | - public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '') |
|
1497 | - { |
|
1498 | - $btn = ''; |
|
1499 | - if (empty($url) || empty($ID)) { |
|
1500 | - return $btn; |
|
1501 | - } |
|
1502 | - $text = ! empty($text) ? $text : __('Submit', 'event_espresso'); |
|
1503 | - $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
1504 | - if (! $input_only) { |
|
1505 | - $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
1506 | - $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : ''; |
|
1507 | - $btn_frm .= $btn; |
|
1508 | - $btn_frm .= '</form>'; |
|
1509 | - $btn = $btn_frm; |
|
1510 | - unset($btn_frm); |
|
1511 | - } |
|
1512 | - return $btn; |
|
1513 | - } |
|
1423 | + $DTTS = EE_Registry::instance()->load_model('Datetime')->get_dtt_months_and_years($where, $evt_active_status); |
|
1424 | + |
|
1425 | + // let's setup vals for select input helper |
|
1426 | + $options = array( |
|
1427 | + 0 => array( |
|
1428 | + 'text' => __('Select a Month/Year', 'event_espresso'), |
|
1429 | + 'id' => "" |
|
1430 | + ) |
|
1431 | + ); |
|
1432 | + |
|
1433 | + |
|
1434 | + |
|
1435 | + // translate month and date |
|
1436 | + global $wp_locale; |
|
1437 | + |
|
1438 | + foreach ($DTTS as $DTT) { |
|
1439 | + $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1440 | + $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1441 | + $options[] = array( |
|
1442 | + 'text' => $localized_date, |
|
1443 | + 'id' => $id |
|
1444 | + ); |
|
1445 | + } |
|
1446 | + |
|
1447 | + |
|
1448 | + return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1449 | + } |
|
1450 | + |
|
1451 | + |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * generates the dropdown selector for event categories |
|
1455 | + * typically used as a filter on list tables. |
|
1456 | + * @param integer $current_cat currently selected category |
|
1457 | + * @return string html for dropdown |
|
1458 | + */ |
|
1459 | + public static function generate_event_category_dropdown($current_cat = -1) |
|
1460 | + { |
|
1461 | + $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
1462 | + $options = array( |
|
1463 | + '0' => array( |
|
1464 | + 'text' => __('All Categories', 'event_espresso'), |
|
1465 | + 'id' => -1 |
|
1466 | + ) |
|
1467 | + ); |
|
1468 | + |
|
1469 | + // setup categories for dropdown |
|
1470 | + foreach ($categories as $category) { |
|
1471 | + $options[] = array( |
|
1472 | + 'text' => $category->get('name'), |
|
1473 | + 'id' => $category->ID() |
|
1474 | + ); |
|
1475 | + } |
|
1476 | + |
|
1477 | + return self::select_input('EVT_CAT', $options, $current_cat); |
|
1478 | + } |
|
1479 | + |
|
1480 | + |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * generate a submit button with or without it's own microform |
|
1484 | + * this is the only way to create buttons that are compatible across all themes |
|
1485 | + * |
|
1486 | + * @access public |
|
1487 | + * @param string $url - the form action |
|
1488 | + * @param string $ID - some kind of unique ID, appended with "-sbmt" for the input and "-frm" for the form |
|
1489 | + * @param string $class - css classes (separated by spaces if more than one) |
|
1490 | + * @param string $text - what appears on the button |
|
1491 | + * @param string $nonce_action - if using nonces |
|
1492 | + * @param bool|string $input_only - whether to print form header and footer. TRUE returns the input without the form |
|
1493 | + * @param string $extra_attributes - any extra attributes that need to be attached to the form input |
|
1494 | + * @return void |
|
1495 | + */ |
|
1496 | + public static function submit_button($url = '', $ID = '', $class = '', $text = '', $nonce_action = '', $input_only = false, $extra_attributes = '') |
|
1497 | + { |
|
1498 | + $btn = ''; |
|
1499 | + if (empty($url) || empty($ID)) { |
|
1500 | + return $btn; |
|
1501 | + } |
|
1502 | + $text = ! empty($text) ? $text : __('Submit', 'event_espresso'); |
|
1503 | + $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
1504 | + if (! $input_only) { |
|
1505 | + $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
1506 | + $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : ''; |
|
1507 | + $btn_frm .= $btn; |
|
1508 | + $btn_frm .= '</form>'; |
|
1509 | + $btn = $btn_frm; |
|
1510 | + unset($btn_frm); |
|
1511 | + } |
|
1512 | + return $btn; |
|
1513 | + } |
|
1514 | 1514 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | $required = isset($input_value['required']) && $input_value['required'] ? ' <span>*</span>: ' : ': '; |
91 | 91 | // and the css class "required" |
92 | 92 | $css_class = isset($input_value['css_class']) ? $input_value['css_class'] : ''; |
93 | - $styles = $input_value['required'] ? 'required ' . $css_class : $css_class; |
|
93 | + $styles = $input_value['required'] ? 'required '.$css_class : $css_class; |
|
94 | 94 | |
95 | - $field_id = ($id) ? $id . '-' . $input_key : $input_key; |
|
96 | - $tabindex = !empty($input_value['tabindex']) ? ' tabindex="' . $input_value['tabindex'] . '"' : ''; |
|
95 | + $field_id = ($id) ? $id.'-'.$input_key : $input_key; |
|
96 | + $tabindex = ! empty($input_value['tabindex']) ? ' tabindex="'.$input_value['tabindex'].'"' : ''; |
|
97 | 97 | |
98 | 98 | // rows or cols? |
99 | 99 | $rows = isset($input_value['rows']) ? $input_value['rows'] : '10'; |
@@ -102,21 +102,21 @@ discard block |
||
102 | 102 | // any content? |
103 | 103 | $append_content = $input_value['append_content']; |
104 | 104 | |
105 | - $output .= (!$close) ? '<ul>' : ''; |
|
105 | + $output .= ( ! $close) ? '<ul>' : ''; |
|
106 | 106 | $output .= '<li>'; |
107 | 107 | |
108 | 108 | // what type of input are we dealing with ? |
109 | 109 | switch ($input_value['input']) { |
110 | 110 | // text inputs |
111 | 111 | case 'text': |
112 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
113 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" class="' . $styles . '" type="text" value="' . esc_textarea($input_value['value']) . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
112 | + $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>'; |
|
113 | + $output .= "\n\t\t\t".'<input id="'.$field_id.'" class="'.$styles.'" type="text" value="'.esc_textarea($input_value['value']).'" name="'.$input_value['name'].'"'.$tabindex.'>'; |
|
114 | 114 | break; |
115 | 115 | |
116 | 116 | // dropdowns |
117 | 117 | case 'select': |
118 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
119 | - $output .= "\n\t\t\t" . '<select id="' . $field_id . '" class="' . $styles . '" name="' . $input_value['name'] . '"' . $tabindex . '>'; |
|
118 | + $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>'; |
|
119 | + $output .= "\n\t\t\t".'<select id="'.$field_id.'" class="'.$styles.'" name="'.$input_value['name'].'"'.$tabindex.'>'; |
|
120 | 120 | |
121 | 121 | if (is_array($input_value['options'])) { |
122 | 122 | $options = $input_value['options']; |
@@ -127,27 +127,27 @@ discard block |
||
127 | 127 | foreach ($options as $key => $value) { |
128 | 128 | $selected = isset($input_value['value']) && $input_value['value'] == $key ? 'selected=selected' : ''; |
129 | 129 | // $key = str_replace( ' ', '_', sanitize_key( $value )); |
130 | - $output .= "\n\t\t\t\t" . '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>'; |
|
130 | + $output .= "\n\t\t\t\t".'<option '.$selected.' value="'.$key.'">'.$value.'</option>'; |
|
131 | 131 | } |
132 | - $output .= "\n\t\t\t" . '</select>'; |
|
132 | + $output .= "\n\t\t\t".'</select>'; |
|
133 | 133 | |
134 | 134 | break; |
135 | 135 | |
136 | 136 | case 'textarea': |
137 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
138 | - $output .= "\n\t\t\t" . '<textarea id="' . $field_id . '" class="' . $styles . '" rows="' . $rows . '" cols="' . $cols . '" name="' . $input_value['name'] . '"' . $tabindex . '>' . esc_textarea($input_value['value']) . '</textarea>'; |
|
137 | + $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>'; |
|
138 | + $output .= "\n\t\t\t".'<textarea id="'.$field_id.'" class="'.$styles.'" rows="'.$rows.'" cols="'.$cols.'" name="'.$input_value['name'].'"'.$tabindex.'>'.esc_textarea($input_value['value']).'</textarea>'; |
|
139 | 139 | break; |
140 | 140 | |
141 | 141 | case 'hidden': |
142 | 142 | $close = false; |
143 | 143 | $output .= "</li></ul>"; |
144 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="hidden" name="' . $input_value['name'] . '" value="' . $input_value['value'] . '">'; |
|
144 | + $output .= "\n\t\t\t".'<input id="'.$field_id.'" type="hidden" name="'.$input_value['name'].'" value="'.$input_value['value'].'">'; |
|
145 | 145 | break; |
146 | 146 | |
147 | 147 | case 'checkbox': |
148 | - $checked = ( $input_value['value'] == 1 ) ? 'checked="checked"' : ''; |
|
149 | - $output .= "\n\t\t\t" . '<label for="' . $field_id . '">' . $input_value['label'] . $required . '</label>'; |
|
150 | - $output .= "\n\t\t\t" . '<input id="' . $field_id . '" type="checkbox" name="' . $input_value['name'] . '" value="1"' . $checked . $tabindex . ' />'; |
|
148 | + $checked = ($input_value['value'] == 1) ? 'checked="checked"' : ''; |
|
149 | + $output .= "\n\t\t\t".'<label for="'.$field_id.'">'.$input_value['label'].$required.'</label>'; |
|
150 | + $output .= "\n\t\t\t".'<input id="'.$field_id.'" type="checkbox" name="'.$input_value['name'].'" value="1"'.$checked.$tabindex.' />'; |
|
151 | 151 | break; |
152 | 152 | |
153 | 153 | case 'wp_editor': |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | ); |
161 | 161 | $output .= '</li>'; |
162 | 162 | $output .= '</ul>'; |
163 | - $output .= '<h4>' . $input_value['label'] . '</h4>'; |
|
163 | + $output .= '<h4>'.$input_value['label'].'</h4>'; |
|
164 | 164 | if ($append_content) { |
165 | 165 | $output .= $append_content; |
166 | 166 | } |
@@ -232,17 +232,17 @@ discard block |
||
232 | 232 | $_fields = wp_parse_args($field_atts, $defaults); |
233 | 233 | extract($_fields); |
234 | 234 | // generate label |
235 | - $label = empty($label) ? '' : '<label for="' . $id . '">' . $label . '</label>'; |
|
235 | + $label = empty($label) ? '' : '<label for="'.$id.'">'.$label.'</label>'; |
|
236 | 236 | // generate field name |
237 | - $f_name = !empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
237 | + $f_name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name; |
|
238 | 238 | |
239 | 239 | // tabindex |
240 | - $tabindex_str = !empty($tabindex) ? ' tabindex="' . $tabindex . '"' : ''; |
|
240 | + $tabindex_str = ! empty($tabindex) ? ' tabindex="'.$tabindex.'"' : ''; |
|
241 | 241 | |
242 | 242 | // we determine what we're building based on the type |
243 | 243 | switch ($type) { |
244 | 244 | case 'textarea': |
245 | - $fld = '<textarea id="' . $id . '" class="' . $class . '" rows="' . $dimensions[1] . '" cols="' . $dimensions[0] . '" name="' . $f_name . '"' . $tabindex_str . '>' . $value . '</textarea>'; |
|
245 | + $fld = '<textarea id="'.$id.'" class="'.$class.'" rows="'.$dimensions[1].'" cols="'.$dimensions[0].'" name="'.$f_name.'"'.$tabindex_str.'>'.$value.'</textarea>'; |
|
246 | 246 | $fld .= $extra_desc; |
247 | 247 | break; |
248 | 248 | |
@@ -250,16 +250,16 @@ discard block |
||
250 | 250 | $c_input = ''; |
251 | 251 | if (is_array($value)) { |
252 | 252 | foreach ($value as $key => $val) { |
253 | - $c_id = $field_name . '_' . $value; |
|
254 | - $c_class = isset($classes[ $key ]) ? ' class="' . $classes[ $key ] . '" ' : ''; |
|
255 | - $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
256 | - $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
257 | - $c_input .= '<input name="' . $f_name . '[]" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
253 | + $c_id = $field_name.'_'.$value; |
|
254 | + $c_class = isset($classes[$key]) ? ' class="'.$classes[$key].'" ' : ''; |
|
255 | + $c_label = isset($labels[$key]) ? '<label for="'.$c_id.'">'.$labels[$key].'</label>' : ''; |
|
256 | + $checked = ! empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
257 | + $c_input .= '<input name="'.$f_name.'[]" type="checkbox" id="'.$c_id.'"'.$c_class.'value="'.$val.'"'.$checked.$tabindex_str.' />'."\n".$c_label; |
|
258 | 258 | } |
259 | 259 | $fld = $c_input; |
260 | 260 | } else { |
261 | - $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
262 | - $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
261 | + $checked = ! empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
262 | + $fld = '<input name="'.$f_name.'" type="checkbox" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$checked.$tabindex_str.' />'."\n"; |
|
263 | 263 | } |
264 | 264 | break; |
265 | 265 | |
@@ -267,28 +267,28 @@ discard block |
||
267 | 267 | $c_input = ''; |
268 | 268 | if (is_array($value)) { |
269 | 269 | foreach ($value as $key => $val) { |
270 | - $c_id = $field_name . '_' . $value; |
|
271 | - $c_class = isset($classes[ $key ]) ? 'class="' . $classes[ $key ] . '" ' : ''; |
|
272 | - $c_label = isset($labels[ $key ]) ? '<label for="' . $c_id . '">' . $labels[ $key ] . '</label>' : ''; |
|
273 | - $checked = !empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
274 | - $c_input .= '<input name="' . $f_name . '" type="checkbox" id="' . $c_id . '"' . $c_class . 'value="' . $val . '"' . $checked . $tabindex_str . ' />' . "\n" . $c_label; |
|
270 | + $c_id = $field_name.'_'.$value; |
|
271 | + $c_class = isset($classes[$key]) ? 'class="'.$classes[$key].'" ' : ''; |
|
272 | + $c_label = isset($labels[$key]) ? '<label for="'.$c_id.'">'.$labels[$key].'</label>' : ''; |
|
273 | + $checked = ! empty($default) && $default == $val ? ' checked="checked" ' : ''; |
|
274 | + $c_input .= '<input name="'.$f_name.'" type="checkbox" id="'.$c_id.'"'.$c_class.'value="'.$val.'"'.$checked.$tabindex_str.' />'."\n".$c_label; |
|
275 | 275 | } |
276 | 276 | $fld = $c_input; |
277 | 277 | } else { |
278 | - $checked = !empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
279 | - $fld = '<input name="' . $f_name . '" type="checkbox" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $checked . $tabindex_str . ' />' . "\n"; |
|
278 | + $checked = ! empty($default) && $default == $val ? 'checked="checked" ' : ''; |
|
279 | + $fld = '<input name="'.$f_name.'" type="checkbox" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$checked.$tabindex_str.' />'."\n"; |
|
280 | 280 | } |
281 | 281 | break; |
282 | 282 | |
283 | 283 | case 'hidden': |
284 | - $fld = '<input name="' . $f_name . '" type="hidden" id="' . $id . '" class="' . $class . '" value="' . $value . '" />' . "\n"; |
|
284 | + $fld = '<input name="'.$f_name.'" type="hidden" id="'.$id.'" class="'.$class.'" value="'.$value.'" />'."\n"; |
|
285 | 285 | break; |
286 | 286 | |
287 | 287 | case 'select': |
288 | - $fld = '<select name="' . $f_name . '" class="' . $class . '" id="' . $id . '"' . $tabindex_str . '>' . "\n"; |
|
288 | + $fld = '<select name="'.$f_name.'" class="'.$class.'" id="'.$id.'"'.$tabindex_str.'>'."\n"; |
|
289 | 289 | foreach ($value as $key => $val) { |
290 | - $checked = !empty($default) && $default == $val ? ' selected="selected"' : ''; |
|
291 | - $fld .= "\t" . '<option value="' . $val . '"' . $checked . '>' . $labels[ $key ] . '</option>' . "\n"; |
|
290 | + $checked = ! empty($default) && $default == $val ? ' selected="selected"' : ''; |
|
291 | + $fld .= "\t".'<option value="'.$val.'"'.$checked.'>'.$labels[$key].'</option>'."\n"; |
|
292 | 292 | } |
293 | 293 | $fld .= '</select>'; |
294 | 294 | break; |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | break; |
310 | 310 | |
311 | 311 | default: // 'text fields' |
312 | - $fld = '<input name="' . $f_name . '" type="text" id="' . $id . '" class="' . $class . '" value="' . $value . '"' . $tabindex_str . ' />' . "\n"; |
|
312 | + $fld = '<input name="'.$f_name.'" type="text" id="'.$id.'" class="'.$class.'" value="'.$value.'"'.$tabindex_str.' />'."\n"; |
|
313 | 313 | $fld .= $extra_desc; |
314 | 314 | } |
315 | 315 | |
316 | - $form_fields[ $field_name ] = array( 'label' => $label, 'field' => $fld ); |
|
316 | + $form_fields[$field_name] = array('label' => $label, 'field' => $fld); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | return $form_fields; |
@@ -343,25 +343,25 @@ discard block |
||
343 | 343 | public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
344 | 344 | { |
345 | 345 | // if $values was submitted in the wrong format, convert it over |
346 | - if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) { |
|
346 | + if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) { |
|
347 | 347 | $converted_values = array(); |
348 | 348 | foreach ($values as $id => $text) { |
349 | - $converted_values[] = array('id' => $id,'text' => $text); |
|
349 | + $converted_values[] = array('id' => $id, 'text' => $text); |
|
350 | 350 | } |
351 | 351 | $values = $converted_values; |
352 | 352 | } |
353 | 353 | |
354 | - $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"'; |
|
354 | + $field = '<select id="'.EEH_Formatter::ee_tep_output_string($name).'" name="'.EEH_Formatter::ee_tep_output_string($name).'"'; |
|
355 | 355 | // Debug |
356 | 356 | // EEH_Debug_Tools::printr( $values, '$values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
357 | 357 | if (EEH_Formatter::ee_tep_not_null($parameters)) { |
358 | - $field .= ' ' . $parameters; |
|
358 | + $field .= ' '.$parameters; |
|
359 | 359 | } |
360 | 360 | if ($autosize) { |
361 | 361 | $size = 'med'; |
362 | 362 | for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
363 | - if ($values[ $ii ]['text']) { |
|
364 | - if (strlen($values[ $ii ]['text']) > 5) { |
|
363 | + if ($values[$ii]['text']) { |
|
364 | + if (strlen($values[$ii]['text']) > 5) { |
|
365 | 365 | $size = 'wide'; |
366 | 366 | } |
367 | 367 | } |
@@ -370,22 +370,22 @@ discard block |
||
370 | 370 | $size = ''; |
371 | 371 | } |
372 | 372 | |
373 | - $field .= ' class="' . $class . ' ' . $size . '">'; |
|
373 | + $field .= ' class="'.$class.' '.$size.'">'; |
|
374 | 374 | |
375 | - if (empty($default) && isset($GLOBALS[ $name ])) { |
|
376 | - $default = stripslashes($GLOBALS[ $name ]); |
|
375 | + if (empty($default) && isset($GLOBALS[$name])) { |
|
376 | + $default = stripslashes($GLOBALS[$name]); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | |
380 | 380 | for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
381 | - $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
382 | - if ($default == $values[ $i ]['id']) { |
|
381 | + $field .= '<option value="'.$values[$i]['id'].'"'; |
|
382 | + if ($default == $values[$i]['id']) { |
|
383 | 383 | $field .= ' selected = "selected"'; |
384 | 384 | } |
385 | - if (isset($values[ $i ]['class'])) { |
|
386 | - $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
385 | + if (isset($values[$i]['class'])) { |
|
386 | + $field .= ' class="'.$values[$i]['class'].'"'; |
|
387 | 387 | } |
388 | - $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
388 | + $field .= '>'.$values[$i]['text'].'</option>'; |
|
389 | 389 | } |
390 | 390 | $field .= '</select>'; |
391 | 391 | |
@@ -410,18 +410,18 @@ discard block |
||
410 | 410 | $before_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
411 | 411 | $after_question_group_questions = apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
412 | 412 | |
413 | - if (! empty($question_groups)) { |
|
413 | + if ( ! empty($question_groups)) { |
|
414 | 414 | // EEH_Debug_Tools::printr( $question_groups, '$question_groups <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
415 | 415 | // loop thru question groups |
416 | 416 | foreach ($question_groups as $QSG) { |
417 | 417 | // check that questions exist |
418 | - if (! empty($QSG['QSG_questions'])) { |
|
418 | + if ( ! empty($QSG['QSG_questions'])) { |
|
419 | 419 | // use fieldsets |
420 | - $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG['QSG_identifier'] . '">'; |
|
420 | + $html .= "\n\t".'<'.$group_wrapper.' class="espresso-question-group-wrap" id="'.$QSG['QSG_identifier'].'">'; |
|
421 | 421 | // group_name |
422 | - $html .= $QSG['QSG_show_group_name'] ? "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . self::prep_answer($QSG['QSG_name']) . '</h5>' : ''; |
|
422 | + $html .= $QSG['QSG_show_group_name'] ? "\n\t\t".'<h5 class="espresso-question-group-title-h5 section-title">'.self::prep_answer($QSG['QSG_name']).'</h5>' : ''; |
|
423 | 423 | // group_desc |
424 | - $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">' . self::prep_answer($QSG['QSG_desc']) . '</div>' : ''; |
|
424 | + $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) ? '<div class="espresso-question-group-desc-pg">'.self::prep_answer($QSG['QSG_desc']).'</div>' : ''; |
|
425 | 425 | |
426 | 426 | $html .= $before_question_group_questions; |
427 | 427 | // loop thru questions |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $html .= self::generate_form_input($QFI); |
436 | 436 | } |
437 | 437 | $html .= $after_question_group_questions; |
438 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
438 | + $html .= "\n\t".'</'.$group_wrapper.'>'; |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | } |
@@ -471,28 +471,28 @@ discard block |
||
471 | 471 | $q_meta = array_merge($default_q_meta, $q_meta); |
472 | 472 | // EEH_Debug_Tools::printr( $q_meta, '$q_meta <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
473 | 473 | |
474 | - if (! empty($question_groups)) { |
|
474 | + if ( ! empty($question_groups)) { |
|
475 | 475 | // EEH_Debug_Tools::printr( $question_groups, '$question_groups <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
476 | 476 | // loop thru question groups |
477 | 477 | foreach ($question_groups as $QSG) { |
478 | 478 | if ($QSG instanceof EE_Question_Group) { |
479 | 479 | // check that questions exist |
480 | 480 | |
481 | - $where = array( 'QST_deleted' => 0 ); |
|
482 | - if (! $from_admin) { |
|
481 | + $where = array('QST_deleted' => 0); |
|
482 | + if ( ! $from_admin) { |
|
483 | 483 | $where['QST_admin_only'] = 0; |
484 | 484 | } |
485 | - $questions = $QSG->questions(array( $where, 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' ))); |
|
486 | - if (! empty($questions)) { |
|
485 | + $questions = $QSG->questions(array($where, 'order_by' => array('Question_Group_Question.QGQ_order' => 'ASC'))); |
|
486 | + if ( ! empty($questions)) { |
|
487 | 487 | // use fieldsets |
488 | - $html .= "\n\t" . '<' . $group_wrapper . ' class="espresso-question-group-wrap" id="' . $QSG->get('QSG_identifier') . '">'; |
|
488 | + $html .= "\n\t".'<'.$group_wrapper.' class="espresso-question-group-wrap" id="'.$QSG->get('QSG_identifier').'">'; |
|
489 | 489 | // group_name |
490 | 490 | if ($QSG->show_group_name()) { |
491 | - $html .= "\n\t\t" . '<h5 class="espresso-question-group-title-h5 section-title">' . $QSG->get_pretty('QSG_name') . '</h5>'; |
|
491 | + $html .= "\n\t\t".'<h5 class="espresso-question-group-title-h5 section-title">'.$QSG->get_pretty('QSG_name').'</h5>'; |
|
492 | 492 | } |
493 | 493 | // group_desc |
494 | 494 | if ($QSG->show_group_desc()) { |
495 | - $html .= '<div class="espresso-question-group-desc-pg">' . $QSG->get_pretty('QSG_desc') . '</div>'; |
|
495 | + $html .= '<div class="espresso-question-group-desc-pg">'.$QSG->get_pretty('QSG_desc').'</div>'; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | $html .= $before_question_group_questions; |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | |
505 | 505 | if (isset($_GET['qstn']) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
506 | 506 | // check for answer in $_GET in case we are reprocessing a form after an error |
507 | - if (isset($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ])) { |
|
508 | - $answer = is_array($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]) ? $_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ] : sanitize_text_field($_GET['qstn'][ $q_meta['input_id'] ][ $qstn_id ]); |
|
507 | + if (isset($_GET['qstn'][$q_meta['input_id']][$qstn_id])) { |
|
508 | + $answer = is_array($_GET['qstn'][$q_meta['input_id']][$qstn_id]) ? $_GET['qstn'][$q_meta['input_id']][$qstn_id] : sanitize_text_field($_GET['qstn'][$q_meta['input_id']][$qstn_id]); |
|
509 | 509 | } |
510 | 510 | } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
511 | 511 | // attendee data from the session |
512 | - $answer = isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
512 | + $answer = isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | $html .= self::generate_form_input($QFI); |
529 | 529 | } |
530 | 530 | $html .= $after_question_group_questions; |
531 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
531 | + $html .= "\n\t".'</'.$group_wrapper.'>'; |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | } |
@@ -567,10 +567,10 @@ discard block |
||
567 | 567 | $disabled = $QFI->get('QST_disabled') ? true : false; |
568 | 568 | $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>'); |
569 | 569 | $QST_required = $QFI->get('QST_required'); |
570 | - $required = $QST_required ? array( 'label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required ) : array(); |
|
570 | + $required = $QST_required ? array('label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required) : array(); |
|
571 | 571 | $use_html_entities = $QFI->get_meta('htmlentities'); |
572 | 572 | $required_text = $QFI->get('QST_required_text') != '' ? $QFI->get('QST_required_text') : __('This field is required', 'event_espresso'); |
573 | - $required_text = $QST_required ? "\n\t\t\t" . '<div class="required-text hidden">' . self::prep_answer($required_text, $use_html_entities) . '</div>' : ''; |
|
573 | + $required_text = $QST_required ? "\n\t\t\t".'<div class="required-text hidden">'.self::prep_answer($required_text, $use_html_entities).'</div>' : ''; |
|
574 | 574 | $label_class = 'espresso-form-input-lbl'; |
575 | 575 | $QST_options = $QFI->options(true, $answer); |
576 | 576 | $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : array(); |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | public static function text($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
630 | 630 | { |
631 | 631 | // need these |
632 | - if (! $question || ! $name) { |
|
632 | + if ( ! $question || ! $name) { |
|
633 | 633 | return null; |
634 | 634 | } |
635 | 635 | // prep the answer |
@@ -637,21 +637,21 @@ discard block |
||
637 | 637 | // prep the required array |
638 | 638 | $required = self::prep_required($required); |
639 | 639 | // set disabled tag |
640 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
640 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
641 | 641 | // ya gots ta have style man!!! |
642 | 642 | $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
643 | 643 | $class = empty($class) ? $txt_class : $class; |
644 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
644 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
645 | 645 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
646 | 646 | |
647 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
647 | + $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>'; |
|
648 | 648 | // filter label but ensure required text comes before it |
649 | 649 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
650 | 650 | |
651 | - $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
651 | + $input_html = "\n\t\t\t".'<input type="text" name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" value="'.esc_attr($answer).'" title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>'; |
|
652 | 652 | |
653 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
654 | - return $label_html . $input_html; |
|
653 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
654 | + return $label_html.$input_html; |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | public static function textarea($question = false, $answer = null, $name = false, $id = '', $class = '', $dimensions = false, $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
676 | 676 | { |
677 | 677 | // need these |
678 | - if (! $question || ! $name) { |
|
678 | + if ( ! $question || ! $name) { |
|
679 | 679 | return null; |
680 | 680 | } |
681 | 681 | // prep the answer |
@@ -685,23 +685,23 @@ discard block |
||
685 | 685 | // make sure $dimensions is an array |
686 | 686 | $dimensions = is_array($dimensions) ? $dimensions : array(); |
687 | 687 | // and set some defaults |
688 | - $dimensions = array_merge(array( 'rows' => 3, 'cols' => 40 ), $dimensions); |
|
688 | + $dimensions = array_merge(array('rows' => 3, 'cols' => 40), $dimensions); |
|
689 | 689 | // set disabled tag |
690 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
690 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
691 | 691 | // ya gots ta have style man!!! |
692 | 692 | $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
693 | 693 | $class = empty($class) ? $txt_class : $class; |
694 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
694 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
695 | 695 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
696 | 696 | |
697 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
697 | + $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>'; |
|
698 | 698 | // filter label but ensure required text comes before it |
699 | 699 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
700 | 700 | |
701 | - $input_html = "\n\t\t\t" . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' . $answer . '</textarea>'; |
|
701 | + $input_html = "\n\t\t\t".'<textarea name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'" title="'.$required['msg'].'" '.$disabled.' '.$extra.'>'.$answer.'</textarea>'; |
|
702 | 702 | |
703 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
704 | - return $label_html . $input_html; |
|
703 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
704 | + return $label_html.$input_html; |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | { |
728 | 728 | |
729 | 729 | // need these |
730 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
730 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
731 | 731 | return null; |
732 | 732 | } |
733 | 733 | // prep the answer |
@@ -735,36 +735,36 @@ discard block |
||
735 | 735 | // prep the required array |
736 | 736 | $required = self::prep_required($required); |
737 | 737 | // set disabled tag |
738 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
738 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
739 | 739 | // ya gots ta have style man!!! |
740 | 740 | $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
741 | 741 | $class = empty($class) ? $txt_class : $class; |
742 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
742 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
743 | 743 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
744 | 744 | |
745 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
745 | + $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>'; |
|
746 | 746 | // filter label but ensure required text comes before it |
747 | 747 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
748 | 748 | |
749 | - $input_html = "\n\t\t\t" . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
749 | + $input_html = "\n\t\t\t".'<select name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" title="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>'; |
|
750 | 750 | // recursively count array elements, to determine total number of options |
751 | 751 | $only_option = count($options, 1) == 1 ? true : false; |
752 | - if (! $only_option) { |
|
752 | + if ( ! $only_option) { |
|
753 | 753 | // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
754 | 754 | $selected = $answer === null ? ' selected="selected"' : ''; |
755 | - $input_html .= $add_please_select_option ? "\n\t\t\t\t" . '<option value=""' . $selected . '>' . __(' - please select - ', 'event_espresso') . '</option>' : ''; |
|
755 | + $input_html .= $add_please_select_option ? "\n\t\t\t\t".'<option value=""'.$selected.'>'.__(' - please select - ', 'event_espresso').'</option>' : ''; |
|
756 | 756 | } |
757 | 757 | foreach ($options as $key => $value) { |
758 | 758 | // if value is an array, then create option groups, else create regular ol' options |
759 | 759 | $input_html .= is_array($value) ? self::_generate_select_option_group($key, $value, $answer, $use_html_entities) : self::_generate_select_option($value->value(), $value->desc(), $answer, $only_option, $use_html_entities); |
760 | 760 | } |
761 | 761 | |
762 | - $input_html .= "\n\t\t\t" . '</select>'; |
|
762 | + $input_html .= "\n\t\t\t".'</select>'; |
|
763 | 763 | |
764 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID); |
|
764 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__select__before_end_wrapper', $input_html, $question, $answer, $name, $id, $class, $system_ID); |
|
765 | 765 | |
766 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
767 | - return $label_html . $input_html; |
|
766 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
767 | + return $label_html.$input_html; |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | */ |
784 | 784 | private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
785 | 785 | { |
786 | - $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
786 | + $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">'; |
|
787 | 787 | foreach ($QSOs as $QSO) { |
788 | 788 | $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
789 | 789 | } |
790 | - $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
790 | + $html .= "\n\t\t\t\t".'</optgroup>'; |
|
791 | 791 | return $html; |
792 | 792 | } |
793 | 793 | |
@@ -807,8 +807,8 @@ discard block |
||
807 | 807 | $key = self::prep_answer($key, $use_html_entities); |
808 | 808 | $value = self::prep_answer($value, $use_html_entities); |
809 | 809 | $value = ! empty($value) ? $value : $key; |
810 | - $selected = ( $answer == $key || $only_option ) ? ' selected="selected"' : ''; |
|
811 | - return "\n\t\t\t\t" . '<option value="' . self::prep_option_value($key) . '"' . $selected . '> ' . $value . ' </option>'; |
|
810 | + $selected = ($answer == $key || $only_option) ? ' selected="selected"' : ''; |
|
811 | + return "\n\t\t\t\t".'<option value="'.self::prep_option_value($key).'"'.$selected.'> '.$value.' </option>'; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | public static function radio($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true, $label_b4 = false, $use_desc_4_label = false) |
836 | 836 | { |
837 | 837 | // need these |
838 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
838 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
839 | 839 | return null; |
840 | 840 | } |
841 | 841 | // prep the answer |
@@ -843,46 +843,46 @@ discard block |
||
843 | 843 | // prep the required array |
844 | 844 | $required = self::prep_required($required); |
845 | 845 | // set disabled tag |
846 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
846 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
847 | 847 | // ya gots ta have style man!!! |
848 | 848 | $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
849 | 849 | $class = ! empty($class) ? $class : 'espresso-radio-btn-inp'; |
850 | 850 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
851 | 851 | |
852 | - $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
852 | + $label_html = $required_text."\n\t\t\t".'<label class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label> '; |
|
853 | 853 | // filter label but ensure required text comes before it |
854 | 854 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
855 | 855 | |
856 | - $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
856 | + $input_html = "\n\t\t\t".'<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$label_class.' '.$class.'-ul">'; |
|
857 | 857 | |
858 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
859 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
858 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
859 | + $class .= ! empty($required['class']) ? ' '.$required['class'] : ''; |
|
860 | 860 | |
861 | 861 | foreach ($options as $OPT) { |
862 | 862 | if ($OPT instanceof EE_Question_Option) { |
863 | 863 | $value = self::prep_option_value($OPT->value()); |
864 | 864 | $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
865 | - $size = $use_desc_4_label ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) : self::get_label_size_class($OPT->value()); |
|
866 | - $desc = $OPT->desc();// no self::prep_answer |
|
865 | + $size = $use_desc_4_label ? self::get_label_size_class($OPT->value().' '.$OPT->desc()) : self::get_label_size_class($OPT->value()); |
|
866 | + $desc = $OPT->desc(); // no self::prep_answer |
|
867 | 867 | $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
868 | 868 | $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
869 | - $opt = '-' . sanitize_key($value); |
|
870 | - |
|
871 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
872 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
873 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
874 | - $input_html .= "\n\t\t\t\t\t\t" . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
875 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span class="espresso-radio-btn-desc">' . $label . '</span>' : ''; |
|
876 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
877 | - $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
878 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
869 | + $opt = '-'.sanitize_key($value); |
|
870 | + |
|
871 | + $input_html .= "\n\t\t\t\t".'<li'.$size.'>'; |
|
872 | + $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">'; |
|
873 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>' : ''; |
|
874 | + $input_html .= "\n\t\t\t\t\t\t".'<input type="radio" name="'.$name.'" id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>'; |
|
875 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span class="espresso-radio-btn-desc">'.$label.'</span>' : ''; |
|
876 | + $input_html .= "\n\t\t\t\t\t".'</label>'; |
|
877 | + $input_html .= $use_desc_4_label ? '' : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>'; |
|
878 | + $input_html .= "\n\t\t\t\t".'</li>'; |
|
879 | 879 | } |
880 | 880 | } |
881 | 881 | |
882 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
882 | + $input_html .= "\n\t\t\t".'</ul>'; |
|
883 | 883 | |
884 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
885 | - return $label_html . $input_html; |
|
884 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
885 | + return $label_html.$input_html; |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | |
@@ -907,62 +907,62 @@ discard block |
||
907 | 907 | public static function checkbox($question = false, $answer = null, $options = false, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $label_b4 = false, $system_ID = false, $use_html_entities = true) |
908 | 908 | { |
909 | 909 | // need these |
910 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
910 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
911 | 911 | return null; |
912 | 912 | } |
913 | 913 | $answer = maybe_unserialize($answer); |
914 | 914 | |
915 | 915 | // prep the answer(s) |
916 | - $answer = is_array($answer) ? $answer : array( sanitize_key($answer) => $answer ); |
|
916 | + $answer = is_array($answer) ? $answer : array(sanitize_key($answer) => $answer); |
|
917 | 917 | |
918 | 918 | foreach ($answer as $key => $value) { |
919 | 919 | $key = self::prep_option_value($key); |
920 | - $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
920 | + $answer[$key] = self::prep_answer($value, $use_html_entities); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | // prep the required array |
924 | 924 | $required = self::prep_required($required); |
925 | 925 | // set disabled tag |
926 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
926 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
927 | 927 | // ya gots ta have style man!!! |
928 | 928 | $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
929 | 929 | $class = empty($class) ? 'espresso-radio-btn-inp' : $class; |
930 | 930 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
931 | 931 | |
932 | - $label_html = $required_text . "\n\t\t\t" . '<label class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label> '; |
|
932 | + $label_html = $required_text."\n\t\t\t".'<label class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label> '; |
|
933 | 933 | // filter label but ensure required text comes before it |
934 | 934 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
935 | 935 | |
936 | - $input_html = "\n\t\t\t" . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
936 | + $input_html = "\n\t\t\t".'<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$label_class.' '.$class.'-ul">'; |
|
937 | 937 | |
938 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
939 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
938 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
939 | + $class .= ! empty($required['class']) ? ' '.$required['class'] : ''; |
|
940 | 940 | |
941 | 941 | foreach ($options as $OPT) { |
942 | - $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
943 | - $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
942 | + $value = $OPT->value(); // self::prep_option_value( $OPT->value() ); |
|
943 | + $size = self::get_label_size_class($OPT->value().' '.$OPT->desc()); |
|
944 | 944 | $text = self::prep_answer($OPT->value()); |
945 | - $desc = $OPT->desc() ; |
|
946 | - $opt = '-' . sanitize_key($value); |
|
945 | + $desc = $OPT->desc(); |
|
946 | + $opt = '-'.sanitize_key($value); |
|
947 | 947 | |
948 | 948 | $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
949 | 949 | |
950 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
951 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
952 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
953 | - $input_html .= "\n\t\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
954 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
955 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
956 | - if (! empty($desc) && $desc != $text) { |
|
957 | - $input_html .= "\n\t\t\t\t\t" . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' . $desc . '</div>'; |
|
950 | + $input_html .= "\n\t\t\t\t".'<li'.$size.'>'; |
|
951 | + $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">'; |
|
952 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : ''; |
|
953 | + $input_html .= "\n\t\t\t\t\t\t".'<input type="checkbox" name="'.$name.'['.$OPT->ID().']" id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>'; |
|
954 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : ''; |
|
955 | + $input_html .= "\n\t\t\t\t\t".'</label>'; |
|
956 | + if ( ! empty($desc) && $desc != $text) { |
|
957 | + $input_html .= "\n\t\t\t\t\t".' <br/><div class="espresso-checkbox-option-desc small-text grey-text">'.$desc.'</div>'; |
|
958 | 958 | } |
959 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
959 | + $input_html .= "\n\t\t\t\t".'</li>'; |
|
960 | 960 | } |
961 | 961 | |
962 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
962 | + $input_html .= "\n\t\t\t".'</ul>'; |
|
963 | 963 | |
964 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
965 | - return $label_html . $input_html; |
|
964 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
965 | + return $label_html.$input_html; |
|
966 | 966 | } |
967 | 967 | |
968 | 968 | |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | public static function datepicker($question = false, $answer = null, $name = false, $id = '', $class = '', $required = false, $required_text = '', $label_class = '', $disabled = false, $system_ID = false, $use_html_entities = true) |
987 | 987 | { |
988 | 988 | // need these |
989 | - if (! $question || ! $name) { |
|
989 | + if ( ! $question || ! $name) { |
|
990 | 990 | return null; |
991 | 991 | } |
992 | 992 | // prep the answer |
@@ -994,26 +994,26 @@ discard block |
||
994 | 994 | // prep the required array |
995 | 995 | $required = self::prep_required($required); |
996 | 996 | // set disabled tag |
997 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
997 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
998 | 998 | // ya gots ta have style man!!! |
999 | 999 | $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
1000 | 1000 | $class = empty($class) ? $txt_class : $class; |
1001 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1001 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1002 | 1002 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
1003 | 1003 | |
1004 | - $label_html = $required_text . "\n\t\t\t" . '<label for="' . $name . '" class="' . $label_class . '">' . self::prep_question($question) . $required['label'] . '</label><br/>'; |
|
1004 | + $label_html = $required_text."\n\t\t\t".'<label for="'.$name.'" class="'.$label_class.'">'.self::prep_question($question).$required['label'].'</label><br/>'; |
|
1005 | 1005 | // filter label but ensure required text comes before it |
1006 | 1006 | $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
1007 | 1007 | |
1008 | - $input_html = "\n\t\t\t" . '<input type="text" name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1008 | + $input_html = "\n\t\t\t".'<input type="text" name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'" title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>'; |
|
1009 | 1009 | |
1010 | 1010 | // enqueue scripts |
1011 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
1011 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
1012 | 1012 | wp_enqueue_style('espresso-ui-theme'); |
1013 | 1013 | wp_enqueue_script('jquery-ui-datepicker'); |
1014 | 1014 | |
1015 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1016 | - return $label_html . $input_html; |
|
1015 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1016 | + return $label_html.$input_html; |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | public static function hidden_input($name, $value, $id = '') |
1043 | 1043 | { |
1044 | 1044 | $id = ! empty($id) ? $id : $name; |
1045 | - return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1045 | + return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>'; |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1100,14 +1100,14 @@ discard block |
||
1100 | 1100 | $prepped_answer_options = array(); |
1101 | 1101 | if (is_array($QSOs) && ! empty($QSOs)) { |
1102 | 1102 | foreach ($QSOs as $key => $QSO) { |
1103 | - if (! $QSO instanceof EE_Question_Option) { |
|
1103 | + if ( ! $QSO instanceof EE_Question_Option) { |
|
1104 | 1104 | $QSO = EE_Question_Option::new_instance(array( |
1105 | 1105 | 'QSO_value' => is_array($QSO) && isset($QSO['id']) ? (string) $QSO['id'] : (string) $key, |
1106 | 1106 | 'QSO_desc' => is_array($QSO) && isset($QSO['text']) ? (string) $QSO['text'] : (string) $QSO |
1107 | 1107 | )); |
1108 | 1108 | } |
1109 | 1109 | if ($QSO->opt_group()) { |
1110 | - $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1110 | + $prepped_answer_options[$QSO->opt_group()][] = $QSO; |
|
1111 | 1111 | } else { |
1112 | 1112 | $prepped_answer_options[] = $QSO; |
1113 | 1113 | } |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | // make sure required is an array |
1142 | 1142 | $required = is_array($required) ? $required : array(); |
1143 | 1143 | // and set some defaults |
1144 | - $required = array_merge(array( 'label' => '', 'class' => '', 'msg' => '' ), $required); |
|
1144 | + $required = array_merge(array('label' => '', 'class' => '', 'msg' => ''), $required); |
|
1145 | 1145 | return $required; |
1146 | 1146 | } |
1147 | 1147 | |
@@ -1161,22 +1161,22 @@ discard block |
||
1161 | 1161 | $val_size = strlen($value); |
1162 | 1162 | switch ($val_size) { |
1163 | 1163 | case $val_size < 3: |
1164 | - $size = ' class="nano-lbl"'; |
|
1164 | + $size = ' class="nano-lbl"'; |
|
1165 | 1165 | break; |
1166 | 1166 | case $val_size < 6: |
1167 | - $size = ' class="micro-lbl"'; |
|
1167 | + $size = ' class="micro-lbl"'; |
|
1168 | 1168 | break; |
1169 | 1169 | case $val_size < 12: |
1170 | - $size = ' class="tiny-lbl"'; |
|
1170 | + $size = ' class="tiny-lbl"'; |
|
1171 | 1171 | break; |
1172 | 1172 | case $val_size < 25: |
1173 | - $size = ' class="small-lbl"'; |
|
1173 | + $size = ' class="small-lbl"'; |
|
1174 | 1174 | break; |
1175 | 1175 | case $val_size > 100: |
1176 | - $size = ' class="big-lbl"'; |
|
1176 | + $size = ' class="big-lbl"'; |
|
1177 | 1177 | break; |
1178 | 1178 | default: |
1179 | - $size = ' class="medium-lbl"'; |
|
1179 | + $size = ' class="medium-lbl"'; |
|
1180 | 1180 | break; |
1181 | 1181 | } |
1182 | 1182 | return $size; |
@@ -1250,7 +1250,7 @@ discard block |
||
1250 | 1250 | // if multiple countries, we'll create option groups within the dropdown |
1251 | 1251 | foreach ($states as $state) { |
1252 | 1252 | if ($state instanceof EE_State) { |
1253 | - $QSO = EE_Question_Option::new_instance(array ( |
|
1253 | + $QSO = EE_Question_Option::new_instance(array( |
|
1254 | 1254 | 'QSO_value' => $state->ID(), |
1255 | 1255 | 'QSO_desc' => $state->name(), |
1256 | 1256 | 'QST_ID' => $QST->get('QST_ID'), |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | // now add countries |
1284 | 1284 | foreach ($countries as $country) { |
1285 | 1285 | if ($country instanceof EE_Country) { |
1286 | - $QSO = EE_Question_Option::new_instance(array ( |
|
1286 | + $QSO = EE_Question_Option::new_instance(array( |
|
1287 | 1287 | 'QSO_value' => $country->ID(), |
1288 | 1288 | 'QSO_desc' => $country->name(), |
1289 | 1289 | 'QST_ID' => $QST->get('QST_ID'), |
@@ -1309,7 +1309,7 @@ discard block |
||
1309 | 1309 | $options = array(); |
1310 | 1310 | for ($x = 1; $x <= 12; $x++) { |
1311 | 1311 | $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
1312 | - $options[ (string) $mm ] = (string) $mm; |
|
1312 | + $options[(string) $mm] = (string) $mm; |
|
1313 | 1313 | } |
1314 | 1314 | return EEH_Form_Fields::prep_answer_options($options); |
1315 | 1315 | } |
@@ -1329,7 +1329,7 @@ discard block |
||
1329 | 1329 | $next_decade = $current_year + 10; |
1330 | 1330 | for ($x = $current_year; $x <= $next_decade; $x++) { |
1331 | 1331 | $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
1332 | - $options[ (string) $yy ] = (string) $yy; |
|
1332 | + $options[(string) $yy] = (string) $yy; |
|
1333 | 1333 | } |
1334 | 1334 | return EEH_Form_Fields::prep_answer_options($options); |
1335 | 1335 | } |
@@ -1348,7 +1348,7 @@ discard block |
||
1348 | 1348 | public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
1349 | 1349 | { |
1350 | 1350 | $_where = array(); |
1351 | - if (!empty($status)) { |
|
1351 | + if ( ! empty($status)) { |
|
1352 | 1352 | $_where['STS_ID'] = $status; |
1353 | 1353 | } |
1354 | 1354 | |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | ); |
1368 | 1368 | |
1369 | 1369 | foreach ($regdtts as $regdtt) { |
1370 | - $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1370 | + $date = $regdtt->reg_month.' '.$regdtt->reg_year; |
|
1371 | 1371 | $options[] = array( |
1372 | 1372 | 'text' => $date, |
1373 | 1373 | 'id' => $date |
@@ -1397,11 +1397,11 @@ discard block |
||
1397 | 1397 | case 'today': |
1398 | 1398 | case null: |
1399 | 1399 | case 'all': |
1400 | - $where['Event.status'] = array( 'NOT IN', array('trash') ); |
|
1400 | + $where['Event.status'] = array('NOT IN', array('trash')); |
|
1401 | 1401 | break; |
1402 | 1402 | |
1403 | 1403 | case 'draft': |
1404 | - $where['Event.status'] = array( 'IN', array('draft', 'auto-draft') ); |
|
1404 | + $where['Event.status'] = array('IN', array('draft', 'auto-draft')); |
|
1405 | 1405 | |
1406 | 1406 | default: |
1407 | 1407 | $where['Event.status'] = $status; |
@@ -1412,7 +1412,7 @@ discard block |
||
1412 | 1412 | // categories? |
1413 | 1413 | |
1414 | 1414 | |
1415 | - if (!empty($evt_category)) { |
|
1415 | + if ( ! empty($evt_category)) { |
|
1416 | 1416 | $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
1417 | 1417 | $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
1418 | 1418 | } |
@@ -1436,8 +1436,8 @@ discard block |
||
1436 | 1436 | global $wp_locale; |
1437 | 1437 | |
1438 | 1438 | foreach ($DTTS as $DTT) { |
1439 | - $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1440 | - $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1439 | + $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year; |
|
1440 | + $id = $DTT->dtt_month.' '.$DTT->dtt_year; |
|
1441 | 1441 | $options[] = array( |
1442 | 1442 | 'text' => $localized_date, |
1443 | 1443 | 'id' => $id |
@@ -1500,10 +1500,10 @@ discard block |
||
1500 | 1500 | return $btn; |
1501 | 1501 | } |
1502 | 1502 | $text = ! empty($text) ? $text : __('Submit', 'event_espresso'); |
1503 | - $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
1504 | - if (! $input_only) { |
|
1505 | - $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
1506 | - $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) : ''; |
|
1503 | + $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" type="submit" value="'.$text.'" '.$extra_attributes.'/>'; |
|
1504 | + if ( ! $input_only) { |
|
1505 | + $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">'; |
|
1506 | + $btn_frm .= ! empty($nonce_action) ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false) : ''; |
|
1507 | 1507 | $btn_frm .= $btn; |
1508 | 1508 | $btn_frm .= '</form>'; |
1509 | 1509 | $btn = $btn_frm; |
@@ -73,6 +73,7 @@ |
||
73 | 73 | * [ee_tep_not_null description] |
74 | 74 | * |
75 | 75 | * @param string | array $value [description] |
76 | + * @param string $value |
|
76 | 77 | * @return bool [description] |
77 | 78 | */ |
78 | 79 | public static function ee_tep_not_null($value) |
@@ -12,108 +12,108 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * _admin_format_content |
|
17 | - * Text formatting function for wp_editor. |
|
18 | - * This should fix all of the formatting issues of text output from the database. |
|
19 | - * |
|
20 | - * @static |
|
21 | - * @access public |
|
22 | - * @param string $content content to format |
|
23 | - * @return string formatted content |
|
24 | - */ |
|
25 | - public static function admin_format_content($content = '') |
|
26 | - { |
|
27 | - return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | - } |
|
15 | + /** |
|
16 | + * _admin_format_content |
|
17 | + * Text formatting function for wp_editor. |
|
18 | + * This should fix all of the formatting issues of text output from the database. |
|
19 | + * |
|
20 | + * @static |
|
21 | + * @access public |
|
22 | + * @param string $content content to format |
|
23 | + * @return string formatted content |
|
24 | + */ |
|
25 | + public static function admin_format_content($content = '') |
|
26 | + { |
|
27 | + return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * ee_tep_output_string |
|
34 | - * todo: we need a description for this. |
|
35 | - * |
|
36 | - * @static |
|
37 | - * @access public |
|
38 | - * @param string $string string to handle |
|
39 | - * @param boolean $translate //todo what is this for? |
|
40 | - * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | - { |
|
45 | - if ($protected === true) { |
|
46 | - return htmlspecialchars($string); |
|
47 | - } else { |
|
48 | - if ($translate === false) { |
|
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | - } else { |
|
51 | - return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
32 | + /** |
|
33 | + * ee_tep_output_string |
|
34 | + * todo: we need a description for this. |
|
35 | + * |
|
36 | + * @static |
|
37 | + * @access public |
|
38 | + * @param string $string string to handle |
|
39 | + * @param boolean $translate //todo what is this for? |
|
40 | + * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | + { |
|
45 | + if ($protected === true) { |
|
46 | + return htmlspecialchars($string); |
|
47 | + } else { |
|
48 | + if ($translate === false) { |
|
49 | + return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | + } else { |
|
51 | + return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * ee_tep_parse_input_field_data |
|
60 | - * |
|
61 | - * @param string $data string to be "translated" |
|
62 | - * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | - { |
|
67 | - return strtr(trim($data), $parse); |
|
68 | - } |
|
58 | + /** |
|
59 | + * ee_tep_parse_input_field_data |
|
60 | + * |
|
61 | + * @param string $data string to be "translated" |
|
62 | + * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | + { |
|
67 | + return strtr(trim($data), $parse); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * [ee_tep_not_null description] |
|
74 | - * |
|
75 | - * @param string | array $value [description] |
|
76 | - * @return bool [description] |
|
77 | - */ |
|
78 | - public static function ee_tep_not_null($value) |
|
79 | - { |
|
80 | - if (is_array($value)) { |
|
81 | - if (count($value) > 0) { |
|
82 | - return true; |
|
83 | - } else { |
|
84 | - return false; |
|
85 | - } |
|
86 | - } else { |
|
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | - return true; |
|
89 | - } else { |
|
90 | - return false; |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
72 | + /** |
|
73 | + * [ee_tep_not_null description] |
|
74 | + * |
|
75 | + * @param string | array $value [description] |
|
76 | + * @return bool [description] |
|
77 | + */ |
|
78 | + public static function ee_tep_not_null($value) |
|
79 | + { |
|
80 | + if (is_array($value)) { |
|
81 | + if (count($value) > 0) { |
|
82 | + return true; |
|
83 | + } else { |
|
84 | + return false; |
|
85 | + } |
|
86 | + } else { |
|
87 | + if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | + return true; |
|
89 | + } else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Formats a date |
|
99 | - * |
|
100 | - * @param string $date |
|
101 | - * @param string $format - format for the date |
|
102 | - * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | - * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | - * @return string |
|
105 | - * @deprecated v4.6.21 |
|
106 | - */ |
|
107 | - public static function event_date_display($date, $format = '') |
|
108 | - { |
|
109 | - EE_Error::doing_it_wrong( |
|
110 | - __METHOD__, |
|
111 | - __( |
|
112 | - 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - '4.6.21' |
|
116 | - ); |
|
117 | - return $date; |
|
118 | - } |
|
97 | + /** |
|
98 | + * Formats a date |
|
99 | + * |
|
100 | + * @param string $date |
|
101 | + * @param string $format - format for the date |
|
102 | + * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | + * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | + * @return string |
|
105 | + * @deprecated v4.6.21 |
|
106 | + */ |
|
107 | + public static function event_date_display($date, $format = '') |
|
108 | + { |
|
109 | + EE_Error::doing_it_wrong( |
|
110 | + __METHOD__, |
|
111 | + __( |
|
112 | + 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + '4.6.21' |
|
116 | + ); |
|
117 | + return $date; |
|
118 | + } |
|
119 | 119 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return htmlspecialchars($string); |
47 | 47 | } else { |
48 | 48 | if ($translate === false) { |
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
49 | + return self::ee_tep_parse_input_field_data($string, array('"' => '"')); |
|
50 | 50 | } else { |
51 | 51 | return self::ee_tep_parse_input_field_data($string, $translate); |
52 | 52 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | } else { |
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
87 | + if (($value !== '') && (strtolower($value) !== 'null') && (strlen(trim($value)) > 0)) { |
|
88 | 88 | return true; |
89 | 89 | } else { |
90 | 90 | return false; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param string $word |
54 | - * @return mixed |
|
54 | + * @return string |
|
55 | 55 | */ |
56 | 56 | public static function singularize_and_upper($word) |
57 | 57 | { |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | /** |
247 | 247 | * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
248 | 248 | * with the new PSR-based naming conventions |
249 | - * @param $word |
|
249 | + * @param string $word |
|
250 | 250 | * @return string |
251 | 251 | */ |
252 | 252 | public static function camelize_all_but_first($word) |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | |
402 | 402 | |
403 | 403 | /** |
404 | - * @param $string |
|
404 | + * @param string $string |
|
405 | 405 | * @return string |
406 | 406 | */ |
407 | 407 | public static function add_indefinite_article($string) |
@@ -33,384 +33,384 @@ |
||
33 | 33 | */ |
34 | 34 | class EEH_Inflector |
35 | 35 | { |
36 | - // ------ CLASS METHODS ------ // |
|
37 | - // ---- Public methods ---- // |
|
38 | - // {{{ pluralize() |
|
39 | - |
|
40 | - /** |
|
41 | - * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | - * @param string $word |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function pluralize_and_lower($word) |
|
46 | - { |
|
47 | - return strtolower(self::pluralize($word)); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param string $word |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public static function singularize_and_upper($word) |
|
57 | - { |
|
58 | - return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Pluralizes English nouns. |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @static |
|
68 | - * @param string $word English noun to pluralize |
|
69 | - * @return string Plural noun |
|
70 | - */ |
|
71 | - public static function pluralize($word) |
|
72 | - { |
|
73 | - $plural = array( |
|
74 | - '/(quiz)$/i' => '\1zes', |
|
75 | - '/^(ox)$/i' => '\1en', |
|
76 | - '/([m|l])ouse$/i' => '\1ice', |
|
77 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | - '/(hive)$/i' => '\1s', |
|
82 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | - '/sis$/i' => 'ses', |
|
84 | - '/([ti])um$/i' => '\1a', |
|
85 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | - '/(bu)s$/i' => '\1ses', |
|
87 | - '/(alias|status)/i' => '\1es', |
|
88 | - '/(octop|vir)us$/i' => '\1i', |
|
89 | - '/(ax|test)is$/i' => '\1es', |
|
90 | - '/s$/i' => 's', |
|
91 | - '/$/' => 's'); |
|
92 | - |
|
93 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | - |
|
95 | - $irregular = array( |
|
96 | - 'person' => 'people', |
|
97 | - 'man' => 'men', |
|
98 | - 'child' => 'children', |
|
99 | - 'sex' => 'sexes', |
|
100 | - 'move' => 'moves'); |
|
101 | - |
|
102 | - $lowercased_word = strtolower($word); |
|
103 | - |
|
104 | - foreach ($uncountable as $_uncountable) { |
|
105 | - if ( |
|
106 | - substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | - ) { |
|
109 | - return $word; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - foreach ($irregular as $_plural => $_singular) { |
|
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - foreach ($plural as $rule => $replacement) { |
|
120 | - if (preg_match($rule, $word)) { |
|
121 | - return preg_replace($rule, $replacement, $word); |
|
122 | - } |
|
123 | - } |
|
124 | - return false; |
|
125 | - } |
|
126 | - |
|
127 | - // }}} |
|
128 | - // {{{ singularize() |
|
129 | - |
|
130 | - /** |
|
131 | - * Singularizes English nouns. |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @static |
|
135 | - * @param string $word English noun to singularize |
|
136 | - * @return string Singular noun. |
|
137 | - */ |
|
138 | - public static function singularize($word) |
|
139 | - { |
|
140 | - $singular = array( |
|
141 | - '/(quiz)zes$/i' => '\1', |
|
142 | - '/(matr)ices$/i' => '\1ix', |
|
143 | - '/(vert|ind)ices$/i' => '\1ex', |
|
144 | - '/^(ox)en/i' => '\1', |
|
145 | - '/(alias|status)es$/i' => '\1', |
|
146 | - '/([octop|vir])i$/i' => '\1us', |
|
147 | - '/(cris|ax|test)es$/i' => '\1is', |
|
148 | - '/(shoe)s$/i' => '\1', |
|
149 | - '/(o)es$/i' => '\1', |
|
150 | - '/(bus)es$/i' => '\1', |
|
151 | - '/([m|l])ice$/i' => '\1ouse', |
|
152 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | - '/(m)ovies$/i' => '\1ovie', |
|
154 | - '/(s)eries$/i' => '\1eries', |
|
155 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | - '/([lr])ves$/i' => '\1f', |
|
157 | - '/(tive)s$/i' => '\1', |
|
158 | - '/(hive)s$/i' => '\1', |
|
159 | - '/([^f])ves$/i' => '\1fe', |
|
160 | - '/(^analy)ses$/i' => '\1sis', |
|
161 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | - '/([ti])a$/i' => '\1um', |
|
163 | - '/(n)ews$/i' => '\1ews', |
|
164 | - '/s$/i' => '', |
|
165 | - ); |
|
166 | - |
|
167 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | - |
|
169 | - $irregular = array( |
|
170 | - 'person' => 'people', |
|
171 | - 'man' => 'men', |
|
172 | - 'child' => 'children', |
|
173 | - 'sex' => 'sexes', |
|
174 | - 'move' => 'moves'); |
|
175 | - |
|
176 | - $lowercased_word = strtolower($word); |
|
177 | - foreach ($uncountable as $_uncountable) { |
|
178 | - if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | - return $word; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - foreach ($irregular as $_plural => $_singular) { |
|
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - foreach ($singular as $rule => $replacement) { |
|
190 | - if (preg_match($rule, $word)) { |
|
191 | - return preg_replace($rule, $replacement, $word); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - return $word; |
|
196 | - } |
|
197 | - |
|
198 | - // }}} |
|
199 | - // {{{ titleize() |
|
200 | - |
|
201 | - /** |
|
202 | - * Converts an underscored or CamelCase word into a English |
|
203 | - * sentence. |
|
204 | - * |
|
205 | - * The titleize static function converts text like "WelcomePage", |
|
206 | - * "welcome_page" or "welcome page" to this "Welcome |
|
207 | - * Page". |
|
208 | - * If second parameter is set to 'first' it will only |
|
209 | - * capitalize the first character of the title. |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @static |
|
213 | - * @param string $word Word to format as tile |
|
214 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | - * first character. Otherwise it will uppercase all |
|
216 | - * the words in the title. |
|
217 | - * @return string Text formatted as title |
|
218 | - */ |
|
219 | - public static function titleize($word, $uppercase = '') |
|
220 | - { |
|
221 | - $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | - } |
|
224 | - |
|
225 | - // }}} |
|
226 | - // {{{ camelize() |
|
227 | - |
|
228 | - /** |
|
229 | - * Returns given word as CamelCased |
|
230 | - * |
|
231 | - * Converts a word like "send_email" to "SendEmail". It |
|
232 | - * will remove non alphanumeric character from the word, so |
|
233 | - * "who's online" will be converted to "WhoSOnline" |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @static |
|
237 | - * @see variablize |
|
238 | - * @param string $word Word to convert to camel case |
|
239 | - * @return string UpperCamelCasedWord |
|
240 | - */ |
|
241 | - public static function camelize($word) |
|
242 | - { |
|
243 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | - * with the new PSR-based naming conventions |
|
251 | - * @param $word |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public static function camelize_all_but_first($word) |
|
255 | - { |
|
256 | - return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | - } |
|
258 | - // }}} |
|
259 | - // {{{ underscore() |
|
260 | - |
|
261 | - /** |
|
262 | - * Converts a word "into_it_s_underscored_version" |
|
263 | - * |
|
264 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | - * "underscored_word". |
|
266 | - * |
|
267 | - * This can be really useful for creating friendly URLs. |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @static |
|
271 | - * @param string $word Word to underscore |
|
272 | - * @return string Underscored word |
|
273 | - */ |
|
274 | - public static function underscore($word) |
|
275 | - { |
|
276 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | - } |
|
278 | - |
|
279 | - // }}} |
|
280 | - // {{{ humanize() |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns a human-readable string from $word |
|
284 | - * |
|
285 | - * Returns a human-readable string from $word, by replacing |
|
286 | - * underscores with a space, and by upper-casing the initial |
|
287 | - * character by default. |
|
288 | - * |
|
289 | - * If you need to uppercase all the words you just have to |
|
290 | - * pass 'all' as a second parameter. |
|
291 | - * |
|
292 | - * @access public |
|
293 | - * @static |
|
294 | - * @param string $word String to "humanize" |
|
295 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | - * instead of just the first one. |
|
297 | - * @return string Human-readable word |
|
298 | - */ |
|
299 | - public static function humanize($word, $uppercase = '') |
|
300 | - { |
|
301 | - // make special exceptions for acronyms |
|
302 | - $word = str_replace('wp_', 'WP_', $word); |
|
303 | - $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | - } |
|
306 | - |
|
307 | - // }}} |
|
308 | - // {{{ variablize() |
|
309 | - |
|
310 | - /** |
|
311 | - * Same as camelize but first char is underscored |
|
312 | - * |
|
313 | - * Converts a word like "send_email" to "sendEmail". It |
|
314 | - * will remove non alphanumeric character from the word, so |
|
315 | - * "who's online" will be converted to "whoSOnline" |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @see camelize |
|
320 | - * @param string $word Word to lowerCamelCase |
|
321 | - * @return string Returns a lowerCamelCasedWord |
|
322 | - */ |
|
323 | - public static function variablize($word) |
|
324 | - { |
|
325 | - $word = EEH_Inflector::camelize($word); |
|
326 | - return strtolower($word[0]) . substr($word, 1); |
|
327 | - } |
|
328 | - |
|
329 | - // }}} |
|
330 | - // {{{ tableize() |
|
331 | - |
|
332 | - /** |
|
333 | - * Converts a class name to its table name according to rails |
|
334 | - * naming conventions. |
|
335 | - * |
|
336 | - * Converts "Person" to "people" |
|
337 | - * |
|
338 | - * @access public |
|
339 | - * @static |
|
340 | - * @see classify |
|
341 | - * @param string $class_name Class name for getting related table_name. |
|
342 | - * @return string plural_table_name |
|
343 | - */ |
|
344 | - public static function tableize($class_name) |
|
345 | - { |
|
346 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | - } |
|
348 | - |
|
349 | - // }}} |
|
350 | - // {{{ classify() |
|
351 | - |
|
352 | - /** |
|
353 | - * Converts a table name to its class name according to rails |
|
354 | - * naming conventions. |
|
355 | - * |
|
356 | - * Converts "people" to "Person" |
|
357 | - * |
|
358 | - * @access public |
|
359 | - * @static |
|
360 | - * @see tableize |
|
361 | - * @param string $table_name Table name for getting related ClassName. |
|
362 | - * @return string SingularClassName |
|
363 | - */ |
|
364 | - public static function classify($table_name) |
|
365 | - { |
|
366 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | - } |
|
368 | - |
|
369 | - // }}} |
|
370 | - // {{{ ordinalize() |
|
371 | - |
|
372 | - /** |
|
373 | - * Converts number to its ordinal English form. |
|
374 | - * |
|
375 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @static |
|
379 | - * @param integer $number Number to get its ordinal value |
|
380 | - * @return string Ordinal representation of given string. |
|
381 | - */ |
|
382 | - public static function ordinalize($number) |
|
383 | - { |
|
384 | - if (in_array(($number % 100), range(11, 13))) { |
|
385 | - return $number . 'th'; |
|
386 | - } else { |
|
387 | - switch (($number % 10)) { |
|
388 | - case 1: |
|
389 | - return $number . 'st'; |
|
390 | - break; |
|
391 | - case 2: |
|
392 | - return $number . 'nd'; |
|
393 | - break; |
|
394 | - case 3: |
|
395 | - return $number . 'rd'; |
|
396 | - default: |
|
397 | - return $number . 'th'; |
|
398 | - break; |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param $string |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public static function add_indefinite_article($string) |
|
410 | - { |
|
411 | - if (strtolower($string) === 'null') { |
|
412 | - return $string; |
|
413 | - } |
|
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | - } |
|
36 | + // ------ CLASS METHODS ------ // |
|
37 | + // ---- Public methods ---- // |
|
38 | + // {{{ pluralize() |
|
39 | + |
|
40 | + /** |
|
41 | + * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | + * @param string $word |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function pluralize_and_lower($word) |
|
46 | + { |
|
47 | + return strtolower(self::pluralize($word)); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param string $word |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public static function singularize_and_upper($word) |
|
57 | + { |
|
58 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Pluralizes English nouns. |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @static |
|
68 | + * @param string $word English noun to pluralize |
|
69 | + * @return string Plural noun |
|
70 | + */ |
|
71 | + public static function pluralize($word) |
|
72 | + { |
|
73 | + $plural = array( |
|
74 | + '/(quiz)$/i' => '\1zes', |
|
75 | + '/^(ox)$/i' => '\1en', |
|
76 | + '/([m|l])ouse$/i' => '\1ice', |
|
77 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | + '/(hive)$/i' => '\1s', |
|
82 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | + '/sis$/i' => 'ses', |
|
84 | + '/([ti])um$/i' => '\1a', |
|
85 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | + '/(bu)s$/i' => '\1ses', |
|
87 | + '/(alias|status)/i' => '\1es', |
|
88 | + '/(octop|vir)us$/i' => '\1i', |
|
89 | + '/(ax|test)is$/i' => '\1es', |
|
90 | + '/s$/i' => 's', |
|
91 | + '/$/' => 's'); |
|
92 | + |
|
93 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | + |
|
95 | + $irregular = array( |
|
96 | + 'person' => 'people', |
|
97 | + 'man' => 'men', |
|
98 | + 'child' => 'children', |
|
99 | + 'sex' => 'sexes', |
|
100 | + 'move' => 'moves'); |
|
101 | + |
|
102 | + $lowercased_word = strtolower($word); |
|
103 | + |
|
104 | + foreach ($uncountable as $_uncountable) { |
|
105 | + if ( |
|
106 | + substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | + ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | + ) { |
|
109 | + return $word; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + foreach ($irregular as $_plural => $_singular) { |
|
114 | + if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + foreach ($plural as $rule => $replacement) { |
|
120 | + if (preg_match($rule, $word)) { |
|
121 | + return preg_replace($rule, $replacement, $word); |
|
122 | + } |
|
123 | + } |
|
124 | + return false; |
|
125 | + } |
|
126 | + |
|
127 | + // }}} |
|
128 | + // {{{ singularize() |
|
129 | + |
|
130 | + /** |
|
131 | + * Singularizes English nouns. |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @static |
|
135 | + * @param string $word English noun to singularize |
|
136 | + * @return string Singular noun. |
|
137 | + */ |
|
138 | + public static function singularize($word) |
|
139 | + { |
|
140 | + $singular = array( |
|
141 | + '/(quiz)zes$/i' => '\1', |
|
142 | + '/(matr)ices$/i' => '\1ix', |
|
143 | + '/(vert|ind)ices$/i' => '\1ex', |
|
144 | + '/^(ox)en/i' => '\1', |
|
145 | + '/(alias|status)es$/i' => '\1', |
|
146 | + '/([octop|vir])i$/i' => '\1us', |
|
147 | + '/(cris|ax|test)es$/i' => '\1is', |
|
148 | + '/(shoe)s$/i' => '\1', |
|
149 | + '/(o)es$/i' => '\1', |
|
150 | + '/(bus)es$/i' => '\1', |
|
151 | + '/([m|l])ice$/i' => '\1ouse', |
|
152 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | + '/(m)ovies$/i' => '\1ovie', |
|
154 | + '/(s)eries$/i' => '\1eries', |
|
155 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | + '/([lr])ves$/i' => '\1f', |
|
157 | + '/(tive)s$/i' => '\1', |
|
158 | + '/(hive)s$/i' => '\1', |
|
159 | + '/([^f])ves$/i' => '\1fe', |
|
160 | + '/(^analy)ses$/i' => '\1sis', |
|
161 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | + '/([ti])a$/i' => '\1um', |
|
163 | + '/(n)ews$/i' => '\1ews', |
|
164 | + '/s$/i' => '', |
|
165 | + ); |
|
166 | + |
|
167 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | + |
|
169 | + $irregular = array( |
|
170 | + 'person' => 'people', |
|
171 | + 'man' => 'men', |
|
172 | + 'child' => 'children', |
|
173 | + 'sex' => 'sexes', |
|
174 | + 'move' => 'moves'); |
|
175 | + |
|
176 | + $lowercased_word = strtolower($word); |
|
177 | + foreach ($uncountable as $_uncountable) { |
|
178 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | + return $word; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + foreach ($irregular as $_plural => $_singular) { |
|
184 | + if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + foreach ($singular as $rule => $replacement) { |
|
190 | + if (preg_match($rule, $word)) { |
|
191 | + return preg_replace($rule, $replacement, $word); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + return $word; |
|
196 | + } |
|
197 | + |
|
198 | + // }}} |
|
199 | + // {{{ titleize() |
|
200 | + |
|
201 | + /** |
|
202 | + * Converts an underscored or CamelCase word into a English |
|
203 | + * sentence. |
|
204 | + * |
|
205 | + * The titleize static function converts text like "WelcomePage", |
|
206 | + * "welcome_page" or "welcome page" to this "Welcome |
|
207 | + * Page". |
|
208 | + * If second parameter is set to 'first' it will only |
|
209 | + * capitalize the first character of the title. |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @static |
|
213 | + * @param string $word Word to format as tile |
|
214 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | + * first character. Otherwise it will uppercase all |
|
216 | + * the words in the title. |
|
217 | + * @return string Text formatted as title |
|
218 | + */ |
|
219 | + public static function titleize($word, $uppercase = '') |
|
220 | + { |
|
221 | + $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | + } |
|
224 | + |
|
225 | + // }}} |
|
226 | + // {{{ camelize() |
|
227 | + |
|
228 | + /** |
|
229 | + * Returns given word as CamelCased |
|
230 | + * |
|
231 | + * Converts a word like "send_email" to "SendEmail". It |
|
232 | + * will remove non alphanumeric character from the word, so |
|
233 | + * "who's online" will be converted to "WhoSOnline" |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @static |
|
237 | + * @see variablize |
|
238 | + * @param string $word Word to convert to camel case |
|
239 | + * @return string UpperCamelCasedWord |
|
240 | + */ |
|
241 | + public static function camelize($word) |
|
242 | + { |
|
243 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | + * with the new PSR-based naming conventions |
|
251 | + * @param $word |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public static function camelize_all_but_first($word) |
|
255 | + { |
|
256 | + return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | + } |
|
258 | + // }}} |
|
259 | + // {{{ underscore() |
|
260 | + |
|
261 | + /** |
|
262 | + * Converts a word "into_it_s_underscored_version" |
|
263 | + * |
|
264 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | + * "underscored_word". |
|
266 | + * |
|
267 | + * This can be really useful for creating friendly URLs. |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @static |
|
271 | + * @param string $word Word to underscore |
|
272 | + * @return string Underscored word |
|
273 | + */ |
|
274 | + public static function underscore($word) |
|
275 | + { |
|
276 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | + } |
|
278 | + |
|
279 | + // }}} |
|
280 | + // {{{ humanize() |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns a human-readable string from $word |
|
284 | + * |
|
285 | + * Returns a human-readable string from $word, by replacing |
|
286 | + * underscores with a space, and by upper-casing the initial |
|
287 | + * character by default. |
|
288 | + * |
|
289 | + * If you need to uppercase all the words you just have to |
|
290 | + * pass 'all' as a second parameter. |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @static |
|
294 | + * @param string $word String to "humanize" |
|
295 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | + * instead of just the first one. |
|
297 | + * @return string Human-readable word |
|
298 | + */ |
|
299 | + public static function humanize($word, $uppercase = '') |
|
300 | + { |
|
301 | + // make special exceptions for acronyms |
|
302 | + $word = str_replace('wp_', 'WP_', $word); |
|
303 | + $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | + } |
|
306 | + |
|
307 | + // }}} |
|
308 | + // {{{ variablize() |
|
309 | + |
|
310 | + /** |
|
311 | + * Same as camelize but first char is underscored |
|
312 | + * |
|
313 | + * Converts a word like "send_email" to "sendEmail". It |
|
314 | + * will remove non alphanumeric character from the word, so |
|
315 | + * "who's online" will be converted to "whoSOnline" |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @see camelize |
|
320 | + * @param string $word Word to lowerCamelCase |
|
321 | + * @return string Returns a lowerCamelCasedWord |
|
322 | + */ |
|
323 | + public static function variablize($word) |
|
324 | + { |
|
325 | + $word = EEH_Inflector::camelize($word); |
|
326 | + return strtolower($word[0]) . substr($word, 1); |
|
327 | + } |
|
328 | + |
|
329 | + // }}} |
|
330 | + // {{{ tableize() |
|
331 | + |
|
332 | + /** |
|
333 | + * Converts a class name to its table name according to rails |
|
334 | + * naming conventions. |
|
335 | + * |
|
336 | + * Converts "Person" to "people" |
|
337 | + * |
|
338 | + * @access public |
|
339 | + * @static |
|
340 | + * @see classify |
|
341 | + * @param string $class_name Class name for getting related table_name. |
|
342 | + * @return string plural_table_name |
|
343 | + */ |
|
344 | + public static function tableize($class_name) |
|
345 | + { |
|
346 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | + } |
|
348 | + |
|
349 | + // }}} |
|
350 | + // {{{ classify() |
|
351 | + |
|
352 | + /** |
|
353 | + * Converts a table name to its class name according to rails |
|
354 | + * naming conventions. |
|
355 | + * |
|
356 | + * Converts "people" to "Person" |
|
357 | + * |
|
358 | + * @access public |
|
359 | + * @static |
|
360 | + * @see tableize |
|
361 | + * @param string $table_name Table name for getting related ClassName. |
|
362 | + * @return string SingularClassName |
|
363 | + */ |
|
364 | + public static function classify($table_name) |
|
365 | + { |
|
366 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | + } |
|
368 | + |
|
369 | + // }}} |
|
370 | + // {{{ ordinalize() |
|
371 | + |
|
372 | + /** |
|
373 | + * Converts number to its ordinal English form. |
|
374 | + * |
|
375 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @static |
|
379 | + * @param integer $number Number to get its ordinal value |
|
380 | + * @return string Ordinal representation of given string. |
|
381 | + */ |
|
382 | + public static function ordinalize($number) |
|
383 | + { |
|
384 | + if (in_array(($number % 100), range(11, 13))) { |
|
385 | + return $number . 'th'; |
|
386 | + } else { |
|
387 | + switch (($number % 10)) { |
|
388 | + case 1: |
|
389 | + return $number . 'st'; |
|
390 | + break; |
|
391 | + case 2: |
|
392 | + return $number . 'nd'; |
|
393 | + break; |
|
394 | + case 3: |
|
395 | + return $number . 'rd'; |
|
396 | + default: |
|
397 | + return $number . 'th'; |
|
398 | + break; |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param $string |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public static function add_indefinite_article($string) |
|
410 | + { |
|
411 | + if (strtolower($string) === 'null') { |
|
412 | + return $string; |
|
413 | + } |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | + } |
|
416 | 416 | } |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | foreach ($uncountable as $_uncountable) { |
105 | 105 | if ( |
106 | 106 | substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
107 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)]) |
|
108 | 108 | ) { |
109 | 109 | return $word; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | 113 | foreach ($irregular as $_plural => $_singular) { |
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
114 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | foreach ($irregular as $_plural => $_singular) { |
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
184 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | public static function variablize($word) |
324 | 324 | { |
325 | 325 | $word = EEH_Inflector::camelize($word); |
326 | - return strtolower($word[0]) . substr($word, 1); |
|
326 | + return strtolower($word[0]).substr($word, 1); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // }}} |
@@ -382,19 +382,19 @@ discard block |
||
382 | 382 | public static function ordinalize($number) |
383 | 383 | { |
384 | 384 | if (in_array(($number % 100), range(11, 13))) { |
385 | - return $number . 'th'; |
|
385 | + return $number.'th'; |
|
386 | 386 | } else { |
387 | 387 | switch (($number % 10)) { |
388 | 388 | case 1: |
389 | - return $number . 'st'; |
|
389 | + return $number.'st'; |
|
390 | 390 | break; |
391 | 391 | case 2: |
392 | - return $number . 'nd'; |
|
392 | + return $number.'nd'; |
|
393 | 393 | break; |
394 | 394 | case 3: |
395 | - return $number . 'rd'; |
|
395 | + return $number.'rd'; |
|
396 | 396 | default: |
397 | - return $number . 'th'; |
|
397 | + return $number.'th'; |
|
398 | 398 | break; |
399 | 399 | } |
400 | 400 | } |
@@ -411,6 +411,6 @@ discard block |
||
411 | 411 | if (strtolower($string) === 'null') { |
412 | 412 | return $string; |
413 | 413 | } |
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string; |
|
415 | 415 | } |
416 | 416 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * Updates all message templates matching the incoming messengers and message types to active status. |
132 | 132 | * |
133 | 133 | * @static |
134 | - * @param array $messenger_names Messenger slug |
|
134 | + * @param string[] $messenger_names Messenger slug |
|
135 | 135 | * @param array $message_type_names Message type slug |
136 | 136 | * @return int count of updated records. |
137 | 137 | */ |
@@ -451,6 +451,7 @@ discard block |
||
451 | 451 | * @param EE_Registration | null $registration The registration object must be included if this |
452 | 452 | * is going to be a registration trigger url. |
453 | 453 | * @param string $sending_messenger The (optional) sending messenger for the url. |
454 | + * @param EE_Registration $registration |
|
454 | 455 | * |
455 | 456 | * @return string |
456 | 457 | * @throws EE_Error |
@@ -1018,8 +1019,8 @@ discard block |
||
1018 | 1019 | /** |
1019 | 1020 | * @param \EE_messenger $messenger |
1020 | 1021 | * @param \EE_message_type $message_type |
1021 | - * @param $GRP_ID |
|
1022 | - * @param $global |
|
1022 | + * @param integer $GRP_ID |
|
1023 | + * @param boolean $global |
|
1023 | 1024 | * @return array|mixed |
1024 | 1025 | */ |
1025 | 1026 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
@@ -14,1235 +14,1235 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Holds a collection of EE_Message_Template_Pack objects. |
|
19 | - * @type EE_Messages_Template_Pack_Collection |
|
20 | - */ |
|
21 | - protected static $_template_pack_collection; |
|
22 | - |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - private static function _set_autoloader() |
|
27 | - { |
|
28 | - EED_Messages::set_autoloaders(); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * generate_new_templates |
|
34 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
|
35 | - * |
|
36 | - * @access protected |
|
37 | - * @param string $messenger the messenger we are generating templates for |
|
38 | - * @param array $message_types array of message types that the templates are generated for. |
|
39 | - * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. |
|
40 | - * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. |
|
41 | - * @throws \EE_Error |
|
42 | - * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates |
|
43 | - * that are generated. If this is an empty array then it means no templates were generated which usually |
|
44 | - * means there was an error. Anything in the array with an empty value for `MTP_context` means that it |
|
45 | - * was not a new generated template but just reactivated (which only happens for global templates that |
|
46 | - * already exist in the database. |
|
47 | - */ |
|
48 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
49 | - { |
|
50 | - // make sure message_type is an array. |
|
51 | - $message_types = (array) $message_types; |
|
52 | - $templates = array(); |
|
53 | - |
|
54 | - if (empty($messenger)) { |
|
55 | - throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
56 | - } |
|
57 | - |
|
58 | - // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
59 | - if (empty($message_types)) { |
|
60 | - throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
61 | - } |
|
62 | - |
|
63 | - EEH_MSG_Template::_set_autoloader(); |
|
64 | - foreach ($message_types as $message_type) { |
|
65 | - // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
66 | - if ($global && empty($GRP_ID)) { |
|
67 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
68 | - array( |
|
69 | - array( |
|
70 | - 'MTP_messenger' => $messenger, |
|
71 | - 'MTP_message_type' => $message_type, |
|
72 | - 'MTP_is_global' => true, |
|
73 | - ), |
|
74 | - ) |
|
75 | - ); |
|
76 | - $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
77 | - } |
|
78 | - // if this is global template generation. |
|
79 | - // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
80 | - // If we do then NO generation!! |
|
81 | - if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
82 | - $templates[] = array( |
|
83 | - 'GRP_ID' => $GRP_ID, |
|
84 | - 'MTP_context' => '', |
|
85 | - ); |
|
86 | - // we already have generated templates for this so let's go to the next message type. |
|
87 | - continue; |
|
88 | - } |
|
89 | - $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
90 | - |
|
91 | - if (! $new_message_template_group) { |
|
92 | - continue; |
|
93 | - } |
|
94 | - $templates[] = $new_message_template_group; |
|
95 | - } |
|
96 | - |
|
97 | - return $templates; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * The purpose of this method is to determine if there are already generated templates in the database for the given variables. |
|
103 | - * @param string $messenger messenger |
|
104 | - * @param string $message_type message type |
|
105 | - * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
|
106 | - * @return bool true = generated, false = hasn't been generated. |
|
107 | - */ |
|
108 | - public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
109 | - { |
|
110 | - EEH_MSG_Template::_set_autoloader(); |
|
111 | - // what method we use depends on whether we have an GRP_ID or not |
|
112 | - $count = empty($GRP_ID) |
|
113 | - ? EEM_Message_Template::instance()->count( |
|
114 | - array( |
|
115 | - array( |
|
116 | - 'Message_Template_Group.MTP_messenger' => $messenger, |
|
117 | - 'Message_Template_Group.MTP_message_type' => $message_type, |
|
118 | - 'Message_Template_Group.MTP_is_global' => true |
|
119 | - ) |
|
120 | - ) |
|
121 | - ) |
|
122 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
123 | - |
|
124 | - return $count > 0; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Updates all message templates matching the incoming messengers and message types to active status. |
|
132 | - * |
|
133 | - * @static |
|
134 | - * @param array $messenger_names Messenger slug |
|
135 | - * @param array $message_type_names Message type slug |
|
136 | - * @return int count of updated records. |
|
137 | - */ |
|
138 | - public static function update_to_active($messenger_names, $message_type_names) |
|
139 | - { |
|
140 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
141 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
142 | - return EEM_Message_Template_Group::instance()->update( |
|
143 | - array( 'MTP_is_active' => 1 ), |
|
144 | - array( |
|
145 | - array( |
|
146 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
147 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
148 | - ) |
|
149 | - ) |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
157 | - * |
|
158 | - * @static |
|
159 | - * @param array $messenger_names The messenger slugs. |
|
160 | - * If empty then all templates matching the message types are marked inactive. |
|
161 | - * Otherwise only templates matching the messengers and message types. |
|
162 | - * @param array $message_type_names The message type slugs. |
|
163 | - * If empty then all templates matching the messengers are marked inactive. |
|
164 | - * Otherwise only templates matching the messengers and message types. |
|
165 | - * |
|
166 | - * @return int count of updated records. |
|
167 | - */ |
|
168 | - public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
169 | - { |
|
170 | - return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
171 | - $messenger_names, |
|
172 | - $message_type_names |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * The purpose of this function is to return all installed message objects |
|
179 | - * (messengers and message type regardless of whether they are ACTIVE or not) |
|
180 | - * |
|
181 | - * @deprecated 4.9.0 |
|
182 | - * @static |
|
183 | - * @param string $type |
|
184 | - * @return array array consisting of installed messenger objects and installed message type objects. |
|
185 | - */ |
|
186 | - public static function get_installed_message_objects($type = 'all') |
|
187 | - { |
|
188 | - self::_set_autoloader(); |
|
189 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
190 | - return array( |
|
191 | - 'messenger' => $message_resource_manager->installed_messengers(), |
|
192 | - 'message_type' => $message_resource_manager->installed_message_types() |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * This will return an array of shortcodes => labels from the |
|
199 | - * messenger and message_type objects associated with this |
|
200 | - * template. |
|
201 | - * |
|
202 | - * @since 4.3.0 |
|
203 | - * |
|
204 | - * @param string $message_type |
|
205 | - * @param string $messenger |
|
206 | - * @param array $fields What fields we're returning valid shortcodes for. |
|
207 | - * If empty then we assume all fields are to be returned. Optional. |
|
208 | - * @param string $context What context we're going to return shortcodes for. Optional. |
|
209 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
210 | - * but instead an array of the unique shortcodes for all the given ( or all) fields. |
|
211 | - * Optional. |
|
212 | - * @throws \EE_Error |
|
213 | - * @return mixed (array|bool) an array of shortcodes in the format |
|
214 | - * array( '[shortcode] => 'label') |
|
215 | - * OR |
|
216 | - * FALSE if no shortcodes found. |
|
217 | - */ |
|
218 | - public static function get_shortcodes( |
|
219 | - $message_type, |
|
220 | - $messenger, |
|
221 | - $fields = array(), |
|
222 | - $context = 'admin', |
|
223 | - $merged = false |
|
224 | - ) { |
|
225 | - $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
226 | - $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
227 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
228 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
229 | - // convert slug to object |
|
230 | - $messenger = $message_resource_manager->get_messenger($messenger); |
|
231 | - |
|
232 | - // if messenger isn't a EE_messenger resource then bail. |
|
233 | - if (! $messenger instanceof EE_messenger) { |
|
234 | - return array(); |
|
235 | - } |
|
236 | - |
|
237 | - // validate class for getting our list of shortcodes |
|
238 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
239 | - if (! class_exists($classname)) { |
|
240 | - $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
241 | - $msg[] = sprintf( |
|
242 | - __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
243 | - $classname |
|
244 | - ); |
|
245 | - throw new EE_Error(implode('||', $msg)); |
|
246 | - } |
|
247 | - |
|
248 | - /** @type EE_Messages_Validator $_VLD */ |
|
249 | - $_VLD = new $classname(array(), $context); |
|
250 | - $valid_shortcodes = $_VLD->get_validators(); |
|
251 | - |
|
252 | - // let's make sure we're only getting the shortcode part of the validators |
|
253 | - $shortcodes = array(); |
|
254 | - foreach ($valid_shortcodes as $field => $validators) { |
|
255 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
256 | - } |
|
257 | - $valid_shortcodes = $shortcodes; |
|
258 | - |
|
259 | - // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
260 | - if (! empty($fields)) { |
|
261 | - $specified_shortcodes = array(); |
|
262 | - foreach ($fields as $field) { |
|
263 | - if (isset($valid_shortcodes[ $field ])) { |
|
264 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
265 | - } |
|
266 | - } |
|
267 | - $valid_shortcodes = $specified_shortcodes; |
|
268 | - } |
|
269 | - |
|
270 | - // if not merged then let's replace the fields with the localized fields |
|
271 | - if (! $merged) { |
|
272 | - // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
273 | - $field_settings = $messenger->get_template_fields(); |
|
274 | - $localized = array(); |
|
275 | - foreach ($valid_shortcodes as $field => $shortcodes) { |
|
276 | - // get localized field label |
|
277 | - if (isset($field_settings[ $field ])) { |
|
278 | - // possible that this is used as a main field. |
|
279 | - if (empty($field_settings[ $field ])) { |
|
280 | - if (isset($field_settings['extra'][ $field ])) { |
|
281 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
282 | - } else { |
|
283 | - $_field = $field; |
|
284 | - } |
|
285 | - } else { |
|
286 | - $_field = $field_settings[ $field ]['label']; |
|
287 | - } |
|
288 | - } elseif (isset($field_settings['extra'])) { |
|
289 | - // loop through extra "main fields" and see if any of their children have our field |
|
290 | - foreach ($field_settings['extra'] as $main_field => $fields) { |
|
291 | - if (isset($fields[ $field ])) { |
|
292 | - $_field = $fields[ $field ]['label']; |
|
293 | - } else { |
|
294 | - $_field = $field; |
|
295 | - } |
|
296 | - } |
|
297 | - } else { |
|
298 | - $_field = $field; |
|
299 | - } |
|
300 | - if (isset($_field)) { |
|
301 | - $localized[ (string) $_field ] = $shortcodes; |
|
302 | - } |
|
303 | - } |
|
304 | - $valid_shortcodes = $localized; |
|
305 | - } |
|
306 | - |
|
307 | - // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
308 | - if ($merged) { |
|
309 | - $merged_codes = array(); |
|
310 | - foreach ($valid_shortcodes as $field => $shortcode) { |
|
311 | - foreach ($shortcode as $code => $label) { |
|
312 | - if (isset($merged_codes[ $code ])) { |
|
313 | - continue; |
|
314 | - } else { |
|
315 | - $merged_codes[ $code ] = $label; |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
319 | - $valid_shortcodes = $merged_codes; |
|
320 | - } |
|
321 | - |
|
322 | - return $valid_shortcodes; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Get Messenger object. |
|
328 | - * |
|
329 | - * @since 4.3.0 |
|
330 | - * @deprecated 4.9.0 |
|
331 | - * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
332 | - * @throws \EE_Error |
|
333 | - * @return EE_messenger |
|
334 | - */ |
|
335 | - public static function messenger_obj($messenger) |
|
336 | - { |
|
337 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
338 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
339 | - return $Message_Resource_Manager->get_messenger($messenger); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * get Message type object |
|
345 | - * |
|
346 | - * @since 4.3.0 |
|
347 | - * @deprecated 4.9.0 |
|
348 | - * @param string $message_type the slug for the message type object to retrieve |
|
349 | - * @throws \EE_Error |
|
350 | - * @return EE_message_type |
|
351 | - */ |
|
352 | - public static function message_type_obj($message_type) |
|
353 | - { |
|
354 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
355 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
356 | - return $Message_Resource_Manager->get_message_type($message_type); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Given a message_type slug, will return whether that message type is active in the system or not. |
|
365 | - * |
|
366 | - * @since 4.3.0 |
|
367 | - * @param string $message_type message type to check for. |
|
368 | - * @return boolean |
|
369 | - */ |
|
370 | - public static function is_mt_active($message_type) |
|
371 | - { |
|
372 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
373 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
374 | - $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
375 | - return in_array($message_type, $active_mts); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
382 | - * |
|
383 | - * @since 4.3.0 |
|
384 | - * |
|
385 | - * @param string $messenger slug for messenger to check. |
|
386 | - * @return boolean |
|
387 | - */ |
|
388 | - public static function is_messenger_active($messenger) |
|
389 | - { |
|
390 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
391 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
392 | - $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
393 | - return $active_messenger instanceof EE_messenger ? true : false; |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * Used to return active messengers array stored in the wp options table. |
|
400 | - * If no value is present in the option then an empty array is returned. |
|
401 | - * |
|
402 | - * @deprecated 4.9 |
|
403 | - * @since 4.3.1 |
|
404 | - * |
|
405 | - * @return array |
|
406 | - */ |
|
407 | - public static function get_active_messengers_in_db() |
|
408 | - { |
|
409 | - EE_Error::doing_it_wrong( |
|
410 | - __METHOD__, |
|
411 | - __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
412 | - '4.9.0' |
|
413 | - ); |
|
414 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
415 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
416 | - return $Message_Resource_Manager->get_active_messengers_option(); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Used to update the active messengers array stored in the wp options table. |
|
424 | - * |
|
425 | - * @since 4.3.1 |
|
426 | - * @deprecated 4.9.0 |
|
427 | - * |
|
428 | - * @param array $data_to_save Incoming data to save. |
|
429 | - * |
|
430 | - * @return bool FALSE if not updated, TRUE if updated. |
|
431 | - */ |
|
432 | - public static function update_active_messengers_in_db($data_to_save) |
|
433 | - { |
|
434 | - EE_Error::doing_it_wrong( |
|
435 | - __METHOD__, |
|
436 | - __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
437 | - '4.9.0' |
|
438 | - ); |
|
439 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
440 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
441 | - return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
447 | - * appropriate url trigger |
|
448 | - * |
|
449 | - * @param EE_message_type $message_type |
|
450 | - * @param EE_Message $message |
|
451 | - * @param EE_Registration | null $registration The registration object must be included if this |
|
452 | - * is going to be a registration trigger url. |
|
453 | - * @param string $sending_messenger The (optional) sending messenger for the url. |
|
454 | - * |
|
455 | - * @return string |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - public static function get_url_trigger( |
|
459 | - EE_message_type $message_type, |
|
460 | - EE_Message $message, |
|
461 | - $registration = null, |
|
462 | - $sending_messenger = '' |
|
463 | - ) { |
|
464 | - // first determine if the url can be to the EE_Message object. |
|
465 | - if (! $message_type->always_generate()) { |
|
466 | - return EEH_MSG_Template::generate_browser_trigger($message); |
|
467 | - } |
|
468 | - |
|
469 | - // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
470 | - if (! $registration instanceof EE_Registration) { |
|
471 | - throw new EE_Error( |
|
472 | - __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
473 | - ); |
|
474 | - } |
|
475 | - |
|
476 | - // validate given context |
|
477 | - $contexts = $message_type->get_contexts(); |
|
478 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
479 | - throw new EE_Error( |
|
480 | - sprintf( |
|
481 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
482 | - $message->context(), |
|
483 | - get_class($message_type) |
|
484 | - ) |
|
485 | - ); |
|
486 | - } |
|
487 | - |
|
488 | - // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
489 | - if (! empty($sending_messenger)) { |
|
490 | - $with_messengers = $message_type->with_messengers(); |
|
491 | - if ( |
|
492 | - ! isset($with_messengers[ $message->messenger() ]) |
|
493 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
494 | - ) { |
|
495 | - throw new EE_Error( |
|
496 | - sprintf( |
|
497 | - __( |
|
498 | - 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - $sending_messenger, |
|
502 | - get_class($message_type) |
|
503 | - ) |
|
504 | - ); |
|
505 | - } |
|
506 | - } else { |
|
507 | - $sending_messenger = $message->messenger(); |
|
508 | - } |
|
509 | - return EEH_MSG_Template::generate_url_trigger( |
|
510 | - $sending_messenger, |
|
511 | - $message->messenger(), |
|
512 | - $message->context(), |
|
513 | - $message->message_type(), |
|
514 | - $registration, |
|
515 | - $message->GRP_ID() |
|
516 | - ); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
522 | - * @param EE_Message $message |
|
523 | - * @return string. |
|
524 | - */ |
|
525 | - public static function generate_browser_trigger(EE_Message $message) |
|
526 | - { |
|
527 | - $query_args = array( |
|
528 | - 'ee' => 'msg_browser_trigger', |
|
529 | - 'token' => $message->MSG_token() |
|
530 | - ); |
|
531 | - return apply_filters( |
|
532 | - 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
533 | - add_query_arg($query_args, site_url()), |
|
534 | - $message |
|
535 | - ); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
545 | - * @param EE_Message $message |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - public static function generate_error_display_trigger(EE_Message $message) |
|
549 | - { |
|
550 | - return apply_filters( |
|
551 | - 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
552 | - add_query_arg( |
|
553 | - array( |
|
554 | - 'ee' => 'msg_browser_error_trigger', |
|
555 | - 'token' => $message->MSG_token() |
|
556 | - ), |
|
557 | - site_url() |
|
558 | - ), |
|
559 | - $message |
|
560 | - ); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
570 | - * |
|
571 | - * @param string $sending_messenger The sending messenger slug. |
|
572 | - * @param string $generating_messenger The generating messenger slug. |
|
573 | - * @param string $context The context for the template. |
|
574 | - * @param string $message_type The message type slug |
|
575 | - * @param EE_Registration $registration |
|
576 | - * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
577 | - * @param integer $data_id The id to the EE_Base_Class for getting the data used by the trigger. |
|
578 | - * @return string The generated url. |
|
579 | - */ |
|
580 | - public static function generate_url_trigger( |
|
581 | - $sending_messenger, |
|
582 | - $generating_messenger, |
|
583 | - $context, |
|
584 | - $message_type, |
|
585 | - EE_Registration $registration, |
|
586 | - $message_template_group, |
|
587 | - $data_id = 0 |
|
588 | - ) { |
|
589 | - $query_args = array( |
|
590 | - 'ee' => 'msg_url_trigger', |
|
591 | - 'snd_msgr' => $sending_messenger, |
|
592 | - 'gen_msgr' => $generating_messenger, |
|
593 | - 'message_type' => $message_type, |
|
594 | - 'context' => $context, |
|
595 | - 'token' => $registration->reg_url_link(), |
|
596 | - 'GRP_ID' => $message_template_group, |
|
597 | - 'id' => $data_id |
|
598 | - ); |
|
599 | - $url = add_query_arg($query_args, get_home_url()); |
|
600 | - |
|
601 | - // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
602 | - $url = apply_filters( |
|
603 | - 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
604 | - $url, |
|
605 | - $sending_messenger, |
|
606 | - $generating_messenger, |
|
607 | - $context, |
|
608 | - $message_type, |
|
609 | - $registration, |
|
610 | - $message_template_group, |
|
611 | - $data_id |
|
612 | - ); |
|
613 | - return $url; |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Return the specific css for the action icon given. |
|
621 | - * |
|
622 | - * @since 4.9.0 |
|
623 | - * |
|
624 | - * @param string $type What action to return. |
|
625 | - * @return string |
|
626 | - */ |
|
627 | - public static function get_message_action_icon($type) |
|
628 | - { |
|
629 | - $action_icons = self::get_message_action_icons(); |
|
630 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * This is used for retrieving the css classes used for the icons representing message actions. |
|
636 | - * |
|
637 | - * @since 4.9.0 |
|
638 | - * |
|
639 | - * @return array |
|
640 | - */ |
|
641 | - public static function get_message_action_icons() |
|
642 | - { |
|
643 | - return apply_filters( |
|
644 | - 'FHEE__EEH_MSG_Template__message_action_icons', |
|
645 | - array( |
|
646 | - 'view' => array( |
|
647 | - 'label' => __('View Message', 'event_espresso'), |
|
648 | - 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
649 | - ), |
|
650 | - 'error' => array( |
|
651 | - 'label' => __('View Error Message', 'event_espresso'), |
|
652 | - 'css_class' => 'dashicons dashicons-info', |
|
653 | - ), |
|
654 | - 'see_notifications_for' => array( |
|
655 | - 'label' => __('View Related Messages', 'event_espresso'), |
|
656 | - 'css_class' => 'dashicons dashicons-megaphone', |
|
657 | - ), |
|
658 | - 'generate_now' => array( |
|
659 | - 'label' => __('Generate the message now.', 'event_espresso'), |
|
660 | - 'css_class' => 'dashicons dashicons-admin-tools', |
|
661 | - ), |
|
662 | - 'send_now' => array( |
|
663 | - 'label' => __('Send Immediately', 'event_espresso'), |
|
664 | - 'css_class' => 'dashicons dashicons-controls-forward', |
|
665 | - ), |
|
666 | - 'queue_for_resending' => array( |
|
667 | - 'label' => __('Queue for Resending', 'event_espresso'), |
|
668 | - 'css_class' => 'dashicons dashicons-controls-repeat', |
|
669 | - ), |
|
670 | - 'view_transaction' => array( |
|
671 | - 'label' => __('View related Transaction', 'event_espresso'), |
|
672 | - 'css_class' => 'dashicons dashicons-cart', |
|
673 | - ) |
|
674 | - ) |
|
675 | - ); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * This returns the url for a given action related to EE_Message. |
|
681 | - * |
|
682 | - * @since 4.9.0 |
|
683 | - * |
|
684 | - * @param string $type What type of action to return the url for. |
|
685 | - * @param EE_Message $message Required for generating the correct url for some types. |
|
686 | - * @param array $query_params Any additional query params to be included with the generated url. |
|
687 | - * |
|
688 | - * @return string |
|
689 | - */ |
|
690 | - public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
691 | - { |
|
692 | - $action_urls = self::get_message_action_urls($message, $query_params); |
|
693 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * This returns all the current urls for EE_Message actions. |
|
700 | - * |
|
701 | - * @since 4.9.0 |
|
702 | - * |
|
703 | - * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
704 | - * @param array $query_params Any additional query_params to be included with the generated url. |
|
705 | - * |
|
706 | - * @return array |
|
707 | - */ |
|
708 | - public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
709 | - { |
|
710 | - EE_Registry::instance()->load_helper('URL'); |
|
711 | - // if $message is not an instance of EE_Message then let's just do a dummy. |
|
712 | - $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
713 | - $action_urls = apply_filters( |
|
714 | - 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
715 | - array( |
|
716 | - 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
717 | - 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
718 | - 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
719 | - array_merge( |
|
720 | - array( |
|
721 | - 'page' => 'espresso_messages', |
|
722 | - 'action' => 'default', |
|
723 | - 'filterby' => 1, |
|
724 | - ), |
|
725 | - $query_params |
|
726 | - ), |
|
727 | - admin_url('admin.php') |
|
728 | - ), |
|
729 | - 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
730 | - array( |
|
731 | - 'page' => 'espresso_messages', |
|
732 | - 'action' => 'generate_now', |
|
733 | - 'MSG_ID' => $message->ID() |
|
734 | - ), |
|
735 | - admin_url('admin.php') |
|
736 | - ), |
|
737 | - 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
738 | - array( |
|
739 | - 'page' => 'espresso_messages', |
|
740 | - 'action' => 'send_now', |
|
741 | - 'MSG_ID' => $message->ID() |
|
742 | - ), |
|
743 | - admin_url('admin.php') |
|
744 | - ), |
|
745 | - 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
746 | - array( |
|
747 | - 'page' => 'espresso_messages', |
|
748 | - 'action' => 'queue_for_resending', |
|
749 | - 'MSG_ID' => $message->ID() |
|
750 | - ), |
|
751 | - admin_url('admin.php') |
|
752 | - ), |
|
753 | - ) |
|
754 | - ); |
|
755 | - if ( |
|
756 | - $message->TXN_ID() > 0 |
|
757 | - && EE_Registry::instance()->CAP->current_user_can( |
|
758 | - 'ee_read_transaction', |
|
759 | - 'espresso_transactions_default', |
|
760 | - $message->TXN_ID() |
|
761 | - ) |
|
762 | - ) { |
|
763 | - $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
764 | - array( |
|
765 | - 'page' => 'espresso_transactions', |
|
766 | - 'action' => 'view_transaction', |
|
767 | - 'TXN_ID' => $message->TXN_ID() |
|
768 | - ), |
|
769 | - admin_url('admin.php') |
|
770 | - ); |
|
771 | - } else { |
|
772 | - $action_urls['view_transaction'] = ''; |
|
773 | - } |
|
774 | - return $action_urls; |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
780 | - * |
|
781 | - * @since 4.9.0 |
|
782 | - * |
|
783 | - * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
784 | - * empty string is returned) |
|
785 | - * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
786 | - * @param array $query_params Any extra query params to include in the generated link. |
|
787 | - * |
|
788 | - * @return string |
|
789 | - */ |
|
790 | - public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
791 | - { |
|
792 | - $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
793 | - $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
794 | - $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
795 | - |
|
796 | - if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
797 | - return ''; |
|
798 | - } |
|
799 | - |
|
800 | - $icon_css['css_class'] .= esc_attr( |
|
801 | - apply_filters( |
|
802 | - 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
803 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
804 | - $type, |
|
805 | - $message, |
|
806 | - $query_params |
|
807 | - ) |
|
808 | - ); |
|
809 | - |
|
810 | - return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - |
|
815 | - |
|
816 | - |
|
817 | - /** |
|
818 | - * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
819 | - * |
|
820 | - * @since 4.9.0 |
|
821 | - * @return array |
|
822 | - */ |
|
823 | - public static function reg_status_to_message_type_array() |
|
824 | - { |
|
825 | - return (array) apply_filters( |
|
826 | - 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
827 | - array( |
|
828 | - EEM_Registration::status_id_approved => 'registration', |
|
829 | - EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
830 | - EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
831 | - EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
832 | - EEM_Registration::status_id_declined => 'declined_registration' |
|
833 | - ) |
|
834 | - ); |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
842 | - * match, then returns an empty string. |
|
843 | - * |
|
844 | - * @since 4.9.0 |
|
845 | - * @param $reg_status |
|
846 | - * @return string |
|
847 | - */ |
|
848 | - public static function convert_reg_status_to_message_type($reg_status) |
|
849 | - { |
|
850 | - $reg_status_array = self::reg_status_to_message_type_array(); |
|
851 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
852 | - } |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
857 | - * |
|
858 | - * @since 4.9.0 |
|
859 | - * @return array |
|
860 | - */ |
|
861 | - public static function payment_status_to_message_type_array() |
|
862 | - { |
|
863 | - return (array) apply_filters( |
|
864 | - 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
865 | - array( |
|
866 | - EEM_Payment::status_id_approved => 'payment', |
|
867 | - EEM_Payment::status_id_pending => 'payment_pending', |
|
868 | - EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
869 | - EEM_Payment::status_id_declined => 'payment_declined', |
|
870 | - EEM_Payment::status_id_failed => 'payment_failed' |
|
871 | - ) |
|
872 | - ); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - |
|
878 | - /** |
|
879 | - * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
880 | - * an empty string is returned |
|
881 | - * |
|
882 | - * @since 4.9.0 |
|
883 | - * @param $payment_status |
|
884 | - * @return string |
|
885 | - */ |
|
886 | - public static function convert_payment_status_to_message_type($payment_status) |
|
887 | - { |
|
888 | - $payment_status_array = self::payment_status_to_message_type_array(); |
|
889 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * This is used to retrieve the template pack for the given name. |
|
895 | - * |
|
896 | - * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
897 | - * |
|
898 | - * @return EE_Messages_Template_Pack |
|
899 | - */ |
|
900 | - public static function get_template_pack($template_pack_name) |
|
901 | - { |
|
902 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
903 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
904 | - } |
|
905 | - |
|
906 | - // first see if in collection already |
|
907 | - $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
908 | - |
|
909 | - if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
910 | - return $template_pack; |
|
911 | - } |
|
912 | - |
|
913 | - // nope...let's get it. |
|
914 | - // not set yet so let's attempt to get it. |
|
915 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
916 | - ' ', |
|
917 | - '_', |
|
918 | - ucwords( |
|
919 | - str_replace('_', ' ', $template_pack_name) |
|
920 | - ) |
|
921 | - ); |
|
922 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
923 | - return self::get_template_pack('default'); |
|
924 | - } else { |
|
925 | - $template_pack = new $pack_class_name(); |
|
926 | - self::$_template_pack_collection->add($template_pack); |
|
927 | - return $template_pack; |
|
928 | - } |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
936 | - * in it. |
|
937 | - * |
|
938 | - * @since 4.9.0 |
|
939 | - * |
|
940 | - * @return EE_Messages_Template_Pack_Collection |
|
941 | - */ |
|
942 | - public static function get_template_pack_collection() |
|
943 | - { |
|
944 | - $new_collection = false; |
|
945 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
946 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
947 | - $new_collection = true; |
|
948 | - } |
|
949 | - |
|
950 | - // glob the defaults directory for messages |
|
951 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
952 | - foreach ($templates as $template_path) { |
|
953 | - // grab folder name |
|
954 | - $template = basename($template_path); |
|
955 | - |
|
956 | - if (! $new_collection) { |
|
957 | - // already have it? |
|
958 | - if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
959 | - continue; |
|
960 | - } |
|
961 | - } |
|
962 | - |
|
963 | - // setup classname. |
|
964 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
965 | - ' ', |
|
966 | - '_', |
|
967 | - ucwords( |
|
968 | - str_replace( |
|
969 | - '_', |
|
970 | - ' ', |
|
971 | - $template |
|
972 | - ) |
|
973 | - ) |
|
974 | - ); |
|
975 | - if (! class_exists($template_pack_class_name)) { |
|
976 | - continue; |
|
977 | - } |
|
978 | - self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
979 | - } |
|
980 | - |
|
981 | - /** |
|
982 | - * Filter for plugins to add in any additional template packs |
|
983 | - * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
984 | - */ |
|
985 | - $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
986 | - foreach ((array) $additional_template_packs as $template_pack) { |
|
987 | - if ( |
|
988 | - self::$_template_pack_collection->get_by_name( |
|
989 | - $template_pack->dbref |
|
990 | - ) instanceof EE_Messages_Template_Pack |
|
991 | - ) { |
|
992 | - continue; |
|
993 | - } |
|
994 | - self::$_template_pack_collection->add($template_pack); |
|
995 | - } |
|
996 | - return self::$_template_pack_collection; |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * This is a wrapper for the protected _create_new_templates function |
|
1003 | - * |
|
1004 | - * @param string $messenger_name |
|
1005 | - * @param string $message_type_name message type that the templates are being created for |
|
1006 | - * @param int $GRP_ID |
|
1007 | - * @param bool $global |
|
1008 | - * @return array |
|
1009 | - * @throws \EE_Error |
|
1010 | - */ |
|
1011 | - public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
1012 | - { |
|
1013 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
1014 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1015 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
1016 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
1017 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
1018 | - return array(); |
|
1019 | - } |
|
1020 | - // whew made it this far! Okay, let's go ahead and create the templates then |
|
1021 | - return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * @param \EE_messenger $messenger |
|
1028 | - * @param \EE_message_type $message_type |
|
1029 | - * @param $GRP_ID |
|
1030 | - * @param $global |
|
1031 | - * @return array|mixed |
|
1032 | - */ |
|
1033 | - protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
1034 | - { |
|
1035 | - // if we're creating a custom template then we don't need to use the defaults class |
|
1036 | - if (! $global) { |
|
1037 | - return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
1038 | - } |
|
1039 | - /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
1040 | - $Message_Template_Defaults = EE_Registry::factory( |
|
1041 | - 'EE_Messages_Template_Defaults', |
|
1042 | - array( $messenger, $message_type, $GRP_ID ) |
|
1043 | - ); |
|
1044 | - // generate templates |
|
1045 | - $success = $Message_Template_Defaults->create_new_templates(); |
|
1046 | - |
|
1047 | - // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
1048 | - // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
1049 | - // attempts. |
|
1050 | - if (! $success) { |
|
1051 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
1052 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1053 | - $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
1054 | - } |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * $success is in an array in the following format |
|
1058 | - * array( |
|
1059 | - * 'GRP_ID' => $new_grp_id, |
|
1060 | - * 'MTP_context' => $first_context_in_new_templates, |
|
1061 | - * ) |
|
1062 | - */ |
|
1063 | - return $success; |
|
1064 | - } |
|
1065 | - |
|
1066 | - |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * This creates a custom template using the incoming GRP_ID |
|
1070 | - * |
|
1071 | - * @param \EE_messenger $messenger |
|
1072 | - * @param \EE_message_type $message_type |
|
1073 | - * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
1074 | - * @return array $success This will be an array in the format: |
|
1075 | - * array( |
|
1076 | - * 'GRP_ID' => $new_grp_id, |
|
1077 | - * 'MTP_context' => $first_context_in_created_template |
|
1078 | - * ) |
|
1079 | - * @access private |
|
1080 | - */ |
|
1081 | - private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
1082 | - { |
|
1083 | - // defaults |
|
1084 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
1085 | - // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
1086 | - $Message_Template_Group = empty($GRP_ID) |
|
1087 | - ? EEM_Message_Template_Group::instance()->get_one( |
|
1088 | - array( |
|
1089 | - array( |
|
1090 | - 'MTP_messenger' => $messenger->name, |
|
1091 | - 'MTP_message_type' => $message_type->name, |
|
1092 | - 'MTP_is_global' => true |
|
1093 | - ) |
|
1094 | - ) |
|
1095 | - ) |
|
1096 | - : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
1097 | - // if we don't have a mtg at this point then we need to bail. |
|
1098 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
1099 | - EE_Error::add_error( |
|
1100 | - sprintf( |
|
1101 | - __( |
|
1102 | - 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
1103 | - 'event_espresso' |
|
1104 | - ), |
|
1105 | - $GRP_ID |
|
1106 | - ), |
|
1107 | - __FILE__, |
|
1108 | - __FUNCTION__, |
|
1109 | - __LINE__ |
|
1110 | - ); |
|
1111 | - return $success; |
|
1112 | - } |
|
1113 | - // let's get all the related message_template objects for this group. |
|
1114 | - $message_templates = $Message_Template_Group->message_templates(); |
|
1115 | - // now we have what we need to setup the new template |
|
1116 | - $new_mtg = clone $Message_Template_Group; |
|
1117 | - $new_mtg->set('GRP_ID', 0); |
|
1118 | - $new_mtg->set('MTP_is_global', false); |
|
1119 | - $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName']) |
|
1120 | - ? $_POST['templateName'] |
|
1121 | - : __( |
|
1122 | - 'New Custom Template', |
|
1123 | - 'event_espresso' |
|
1124 | - ); |
|
1125 | - $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription']) |
|
1126 | - ? $_POST['templateDescription'] |
|
1127 | - : sprintf( |
|
1128 | - __( |
|
1129 | - 'This is a custom template that was created for the %s messenger and %s message type.', |
|
1130 | - 'event_espresso' |
|
1131 | - ), |
|
1132 | - $new_mtg->messenger_obj()->label['singular'], |
|
1133 | - $new_mtg->message_type_obj()->label['singular'] |
|
1134 | - ); |
|
1135 | - $new_mtg->set('MTP_name', $template_name); |
|
1136 | - $new_mtg->set('MTP_description', $template_description); |
|
1137 | - // remove ALL relations on this template group so they don't get saved! |
|
1138 | - $new_mtg->_remove_relations('Message_Template'); |
|
1139 | - $new_mtg->save(); |
|
1140 | - $success['GRP_ID'] = $new_mtg->ID(); |
|
1141 | - $success['template_name'] = $template_name; |
|
1142 | - // add new message templates and add relation to. |
|
1143 | - foreach ($message_templates as $message_template) { |
|
1144 | - if (! $message_template instanceof EE_Message_Template) { |
|
1145 | - continue; |
|
1146 | - } |
|
1147 | - $new_message_template = clone $message_template; |
|
1148 | - $new_message_template->set('MTP_ID', 0); |
|
1149 | - $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
1150 | - $new_message_template->save(); |
|
1151 | - if (empty($success['MTP_context'])) { |
|
1152 | - $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
1153 | - } |
|
1154 | - } |
|
1155 | - return $success; |
|
1156 | - } |
|
1157 | - |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * message_type_has_active_templates_for_messenger |
|
1162 | - * |
|
1163 | - * @param \EE_messenger $messenger |
|
1164 | - * @param \EE_message_type $message_type |
|
1165 | - * @param bool $global |
|
1166 | - * @return bool |
|
1167 | - */ |
|
1168 | - public static function message_type_has_active_templates_for_messenger( |
|
1169 | - EE_messenger $messenger, |
|
1170 | - EE_message_type $message_type, |
|
1171 | - $global = false |
|
1172 | - ) { |
|
1173 | - // is given message_type valid for given messenger (if this is not a global save) |
|
1174 | - if ($global) { |
|
1175 | - return true; |
|
1176 | - } |
|
1177 | - $active_templates = EEM_Message_Template_Group::instance()->count( |
|
1178 | - array( |
|
1179 | - array( |
|
1180 | - 'MTP_is_active' => true, |
|
1181 | - 'MTP_messenger' => $messenger->name, |
|
1182 | - 'MTP_message_type' => $message_type->name |
|
1183 | - ) |
|
1184 | - ) |
|
1185 | - ); |
|
1186 | - if ($active_templates > 0) { |
|
1187 | - return true; |
|
1188 | - } |
|
1189 | - EE_Error::add_error( |
|
1190 | - sprintf( |
|
1191 | - __( |
|
1192 | - 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
1193 | - 'event_espresso' |
|
1194 | - ), |
|
1195 | - $message_type->name, |
|
1196 | - $messenger->name |
|
1197 | - ), |
|
1198 | - __FILE__, |
|
1199 | - __FUNCTION__, |
|
1200 | - __LINE__ |
|
1201 | - ); |
|
1202 | - return false; |
|
1203 | - } |
|
1204 | - |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * get_fields |
|
1209 | - * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
1210 | - * |
|
1211 | - * @param string $messenger_name name of EE_messenger |
|
1212 | - * @param string $message_type_name name of EE_message_type |
|
1213 | - * @return array |
|
1214 | - */ |
|
1215 | - public static function get_fields($messenger_name, $message_type_name) |
|
1216 | - { |
|
1217 | - $template_fields = array(); |
|
1218 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
1219 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1220 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
1221 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
1222 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
1223 | - return array(); |
|
1224 | - } |
|
1225 | - |
|
1226 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
1227 | - |
|
1228 | - // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
1229 | - foreach ($message_type->get_contexts() as $context => $details) { |
|
1230 | - foreach ($messenger->get_template_fields() as $field => $value) { |
|
1231 | - if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
1232 | - continue; |
|
1233 | - } |
|
1234 | - $template_fields[ $context ][ $field ] = $value; |
|
1235 | - } |
|
1236 | - } |
|
1237 | - if (empty($template_fields)) { |
|
1238 | - EE_Error::add_error( |
|
1239 | - __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
1240 | - __FILE__, |
|
1241 | - __FUNCTION__, |
|
1242 | - __LINE__ |
|
1243 | - ); |
|
1244 | - return array(); |
|
1245 | - } |
|
1246 | - return $template_fields; |
|
1247 | - } |
|
17 | + /** |
|
18 | + * Holds a collection of EE_Message_Template_Pack objects. |
|
19 | + * @type EE_Messages_Template_Pack_Collection |
|
20 | + */ |
|
21 | + protected static $_template_pack_collection; |
|
22 | + |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + private static function _set_autoloader() |
|
27 | + { |
|
28 | + EED_Messages::set_autoloaders(); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * generate_new_templates |
|
34 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
|
35 | + * |
|
36 | + * @access protected |
|
37 | + * @param string $messenger the messenger we are generating templates for |
|
38 | + * @param array $message_types array of message types that the templates are generated for. |
|
39 | + * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. |
|
40 | + * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. |
|
41 | + * @throws \EE_Error |
|
42 | + * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates |
|
43 | + * that are generated. If this is an empty array then it means no templates were generated which usually |
|
44 | + * means there was an error. Anything in the array with an empty value for `MTP_context` means that it |
|
45 | + * was not a new generated template but just reactivated (which only happens for global templates that |
|
46 | + * already exist in the database. |
|
47 | + */ |
|
48 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
49 | + { |
|
50 | + // make sure message_type is an array. |
|
51 | + $message_types = (array) $message_types; |
|
52 | + $templates = array(); |
|
53 | + |
|
54 | + if (empty($messenger)) { |
|
55 | + throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
56 | + } |
|
57 | + |
|
58 | + // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
59 | + if (empty($message_types)) { |
|
60 | + throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
61 | + } |
|
62 | + |
|
63 | + EEH_MSG_Template::_set_autoloader(); |
|
64 | + foreach ($message_types as $message_type) { |
|
65 | + // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
66 | + if ($global && empty($GRP_ID)) { |
|
67 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
68 | + array( |
|
69 | + array( |
|
70 | + 'MTP_messenger' => $messenger, |
|
71 | + 'MTP_message_type' => $message_type, |
|
72 | + 'MTP_is_global' => true, |
|
73 | + ), |
|
74 | + ) |
|
75 | + ); |
|
76 | + $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
77 | + } |
|
78 | + // if this is global template generation. |
|
79 | + // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
80 | + // If we do then NO generation!! |
|
81 | + if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
82 | + $templates[] = array( |
|
83 | + 'GRP_ID' => $GRP_ID, |
|
84 | + 'MTP_context' => '', |
|
85 | + ); |
|
86 | + // we already have generated templates for this so let's go to the next message type. |
|
87 | + continue; |
|
88 | + } |
|
89 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
90 | + |
|
91 | + if (! $new_message_template_group) { |
|
92 | + continue; |
|
93 | + } |
|
94 | + $templates[] = $new_message_template_group; |
|
95 | + } |
|
96 | + |
|
97 | + return $templates; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * The purpose of this method is to determine if there are already generated templates in the database for the given variables. |
|
103 | + * @param string $messenger messenger |
|
104 | + * @param string $message_type message type |
|
105 | + * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
|
106 | + * @return bool true = generated, false = hasn't been generated. |
|
107 | + */ |
|
108 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
109 | + { |
|
110 | + EEH_MSG_Template::_set_autoloader(); |
|
111 | + // what method we use depends on whether we have an GRP_ID or not |
|
112 | + $count = empty($GRP_ID) |
|
113 | + ? EEM_Message_Template::instance()->count( |
|
114 | + array( |
|
115 | + array( |
|
116 | + 'Message_Template_Group.MTP_messenger' => $messenger, |
|
117 | + 'Message_Template_Group.MTP_message_type' => $message_type, |
|
118 | + 'Message_Template_Group.MTP_is_global' => true |
|
119 | + ) |
|
120 | + ) |
|
121 | + ) |
|
122 | + : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
123 | + |
|
124 | + return $count > 0; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Updates all message templates matching the incoming messengers and message types to active status. |
|
132 | + * |
|
133 | + * @static |
|
134 | + * @param array $messenger_names Messenger slug |
|
135 | + * @param array $message_type_names Message type slug |
|
136 | + * @return int count of updated records. |
|
137 | + */ |
|
138 | + public static function update_to_active($messenger_names, $message_type_names) |
|
139 | + { |
|
140 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
141 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
142 | + return EEM_Message_Template_Group::instance()->update( |
|
143 | + array( 'MTP_is_active' => 1 ), |
|
144 | + array( |
|
145 | + array( |
|
146 | + 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
147 | + 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
148 | + ) |
|
149 | + ) |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
157 | + * |
|
158 | + * @static |
|
159 | + * @param array $messenger_names The messenger slugs. |
|
160 | + * If empty then all templates matching the message types are marked inactive. |
|
161 | + * Otherwise only templates matching the messengers and message types. |
|
162 | + * @param array $message_type_names The message type slugs. |
|
163 | + * If empty then all templates matching the messengers are marked inactive. |
|
164 | + * Otherwise only templates matching the messengers and message types. |
|
165 | + * |
|
166 | + * @return int count of updated records. |
|
167 | + */ |
|
168 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
169 | + { |
|
170 | + return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
171 | + $messenger_names, |
|
172 | + $message_type_names |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * The purpose of this function is to return all installed message objects |
|
179 | + * (messengers and message type regardless of whether they are ACTIVE or not) |
|
180 | + * |
|
181 | + * @deprecated 4.9.0 |
|
182 | + * @static |
|
183 | + * @param string $type |
|
184 | + * @return array array consisting of installed messenger objects and installed message type objects. |
|
185 | + */ |
|
186 | + public static function get_installed_message_objects($type = 'all') |
|
187 | + { |
|
188 | + self::_set_autoloader(); |
|
189 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
190 | + return array( |
|
191 | + 'messenger' => $message_resource_manager->installed_messengers(), |
|
192 | + 'message_type' => $message_resource_manager->installed_message_types() |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * This will return an array of shortcodes => labels from the |
|
199 | + * messenger and message_type objects associated with this |
|
200 | + * template. |
|
201 | + * |
|
202 | + * @since 4.3.0 |
|
203 | + * |
|
204 | + * @param string $message_type |
|
205 | + * @param string $messenger |
|
206 | + * @param array $fields What fields we're returning valid shortcodes for. |
|
207 | + * If empty then we assume all fields are to be returned. Optional. |
|
208 | + * @param string $context What context we're going to return shortcodes for. Optional. |
|
209 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
210 | + * but instead an array of the unique shortcodes for all the given ( or all) fields. |
|
211 | + * Optional. |
|
212 | + * @throws \EE_Error |
|
213 | + * @return mixed (array|bool) an array of shortcodes in the format |
|
214 | + * array( '[shortcode] => 'label') |
|
215 | + * OR |
|
216 | + * FALSE if no shortcodes found. |
|
217 | + */ |
|
218 | + public static function get_shortcodes( |
|
219 | + $message_type, |
|
220 | + $messenger, |
|
221 | + $fields = array(), |
|
222 | + $context = 'admin', |
|
223 | + $merged = false |
|
224 | + ) { |
|
225 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
226 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
227 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
228 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
229 | + // convert slug to object |
|
230 | + $messenger = $message_resource_manager->get_messenger($messenger); |
|
231 | + |
|
232 | + // if messenger isn't a EE_messenger resource then bail. |
|
233 | + if (! $messenger instanceof EE_messenger) { |
|
234 | + return array(); |
|
235 | + } |
|
236 | + |
|
237 | + // validate class for getting our list of shortcodes |
|
238 | + $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
239 | + if (! class_exists($classname)) { |
|
240 | + $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
241 | + $msg[] = sprintf( |
|
242 | + __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
243 | + $classname |
|
244 | + ); |
|
245 | + throw new EE_Error(implode('||', $msg)); |
|
246 | + } |
|
247 | + |
|
248 | + /** @type EE_Messages_Validator $_VLD */ |
|
249 | + $_VLD = new $classname(array(), $context); |
|
250 | + $valid_shortcodes = $_VLD->get_validators(); |
|
251 | + |
|
252 | + // let's make sure we're only getting the shortcode part of the validators |
|
253 | + $shortcodes = array(); |
|
254 | + foreach ($valid_shortcodes as $field => $validators) { |
|
255 | + $shortcodes[ $field ] = $validators['shortcodes']; |
|
256 | + } |
|
257 | + $valid_shortcodes = $shortcodes; |
|
258 | + |
|
259 | + // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
260 | + if (! empty($fields)) { |
|
261 | + $specified_shortcodes = array(); |
|
262 | + foreach ($fields as $field) { |
|
263 | + if (isset($valid_shortcodes[ $field ])) { |
|
264 | + $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
265 | + } |
|
266 | + } |
|
267 | + $valid_shortcodes = $specified_shortcodes; |
|
268 | + } |
|
269 | + |
|
270 | + // if not merged then let's replace the fields with the localized fields |
|
271 | + if (! $merged) { |
|
272 | + // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
273 | + $field_settings = $messenger->get_template_fields(); |
|
274 | + $localized = array(); |
|
275 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
276 | + // get localized field label |
|
277 | + if (isset($field_settings[ $field ])) { |
|
278 | + // possible that this is used as a main field. |
|
279 | + if (empty($field_settings[ $field ])) { |
|
280 | + if (isset($field_settings['extra'][ $field ])) { |
|
281 | + $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
282 | + } else { |
|
283 | + $_field = $field; |
|
284 | + } |
|
285 | + } else { |
|
286 | + $_field = $field_settings[ $field ]['label']; |
|
287 | + } |
|
288 | + } elseif (isset($field_settings['extra'])) { |
|
289 | + // loop through extra "main fields" and see if any of their children have our field |
|
290 | + foreach ($field_settings['extra'] as $main_field => $fields) { |
|
291 | + if (isset($fields[ $field ])) { |
|
292 | + $_field = $fields[ $field ]['label']; |
|
293 | + } else { |
|
294 | + $_field = $field; |
|
295 | + } |
|
296 | + } |
|
297 | + } else { |
|
298 | + $_field = $field; |
|
299 | + } |
|
300 | + if (isset($_field)) { |
|
301 | + $localized[ (string) $_field ] = $shortcodes; |
|
302 | + } |
|
303 | + } |
|
304 | + $valid_shortcodes = $localized; |
|
305 | + } |
|
306 | + |
|
307 | + // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
308 | + if ($merged) { |
|
309 | + $merged_codes = array(); |
|
310 | + foreach ($valid_shortcodes as $field => $shortcode) { |
|
311 | + foreach ($shortcode as $code => $label) { |
|
312 | + if (isset($merged_codes[ $code ])) { |
|
313 | + continue; |
|
314 | + } else { |
|
315 | + $merged_codes[ $code ] = $label; |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | + $valid_shortcodes = $merged_codes; |
|
320 | + } |
|
321 | + |
|
322 | + return $valid_shortcodes; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Get Messenger object. |
|
328 | + * |
|
329 | + * @since 4.3.0 |
|
330 | + * @deprecated 4.9.0 |
|
331 | + * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
332 | + * @throws \EE_Error |
|
333 | + * @return EE_messenger |
|
334 | + */ |
|
335 | + public static function messenger_obj($messenger) |
|
336 | + { |
|
337 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
338 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
339 | + return $Message_Resource_Manager->get_messenger($messenger); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * get Message type object |
|
345 | + * |
|
346 | + * @since 4.3.0 |
|
347 | + * @deprecated 4.9.0 |
|
348 | + * @param string $message_type the slug for the message type object to retrieve |
|
349 | + * @throws \EE_Error |
|
350 | + * @return EE_message_type |
|
351 | + */ |
|
352 | + public static function message_type_obj($message_type) |
|
353 | + { |
|
354 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
355 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
356 | + return $Message_Resource_Manager->get_message_type($message_type); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Given a message_type slug, will return whether that message type is active in the system or not. |
|
365 | + * |
|
366 | + * @since 4.3.0 |
|
367 | + * @param string $message_type message type to check for. |
|
368 | + * @return boolean |
|
369 | + */ |
|
370 | + public static function is_mt_active($message_type) |
|
371 | + { |
|
372 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
373 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
374 | + $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
375 | + return in_array($message_type, $active_mts); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
382 | + * |
|
383 | + * @since 4.3.0 |
|
384 | + * |
|
385 | + * @param string $messenger slug for messenger to check. |
|
386 | + * @return boolean |
|
387 | + */ |
|
388 | + public static function is_messenger_active($messenger) |
|
389 | + { |
|
390 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
391 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
392 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
393 | + return $active_messenger instanceof EE_messenger ? true : false; |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * Used to return active messengers array stored in the wp options table. |
|
400 | + * If no value is present in the option then an empty array is returned. |
|
401 | + * |
|
402 | + * @deprecated 4.9 |
|
403 | + * @since 4.3.1 |
|
404 | + * |
|
405 | + * @return array |
|
406 | + */ |
|
407 | + public static function get_active_messengers_in_db() |
|
408 | + { |
|
409 | + EE_Error::doing_it_wrong( |
|
410 | + __METHOD__, |
|
411 | + __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
412 | + '4.9.0' |
|
413 | + ); |
|
414 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
415 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
416 | + return $Message_Resource_Manager->get_active_messengers_option(); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Used to update the active messengers array stored in the wp options table. |
|
424 | + * |
|
425 | + * @since 4.3.1 |
|
426 | + * @deprecated 4.9.0 |
|
427 | + * |
|
428 | + * @param array $data_to_save Incoming data to save. |
|
429 | + * |
|
430 | + * @return bool FALSE if not updated, TRUE if updated. |
|
431 | + */ |
|
432 | + public static function update_active_messengers_in_db($data_to_save) |
|
433 | + { |
|
434 | + EE_Error::doing_it_wrong( |
|
435 | + __METHOD__, |
|
436 | + __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
437 | + '4.9.0' |
|
438 | + ); |
|
439 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
440 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
441 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
447 | + * appropriate url trigger |
|
448 | + * |
|
449 | + * @param EE_message_type $message_type |
|
450 | + * @param EE_Message $message |
|
451 | + * @param EE_Registration | null $registration The registration object must be included if this |
|
452 | + * is going to be a registration trigger url. |
|
453 | + * @param string $sending_messenger The (optional) sending messenger for the url. |
|
454 | + * |
|
455 | + * @return string |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + public static function get_url_trigger( |
|
459 | + EE_message_type $message_type, |
|
460 | + EE_Message $message, |
|
461 | + $registration = null, |
|
462 | + $sending_messenger = '' |
|
463 | + ) { |
|
464 | + // first determine if the url can be to the EE_Message object. |
|
465 | + if (! $message_type->always_generate()) { |
|
466 | + return EEH_MSG_Template::generate_browser_trigger($message); |
|
467 | + } |
|
468 | + |
|
469 | + // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
470 | + if (! $registration instanceof EE_Registration) { |
|
471 | + throw new EE_Error( |
|
472 | + __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
473 | + ); |
|
474 | + } |
|
475 | + |
|
476 | + // validate given context |
|
477 | + $contexts = $message_type->get_contexts(); |
|
478 | + if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
479 | + throw new EE_Error( |
|
480 | + sprintf( |
|
481 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
482 | + $message->context(), |
|
483 | + get_class($message_type) |
|
484 | + ) |
|
485 | + ); |
|
486 | + } |
|
487 | + |
|
488 | + // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
489 | + if (! empty($sending_messenger)) { |
|
490 | + $with_messengers = $message_type->with_messengers(); |
|
491 | + if ( |
|
492 | + ! isset($with_messengers[ $message->messenger() ]) |
|
493 | + || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
494 | + ) { |
|
495 | + throw new EE_Error( |
|
496 | + sprintf( |
|
497 | + __( |
|
498 | + 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + $sending_messenger, |
|
502 | + get_class($message_type) |
|
503 | + ) |
|
504 | + ); |
|
505 | + } |
|
506 | + } else { |
|
507 | + $sending_messenger = $message->messenger(); |
|
508 | + } |
|
509 | + return EEH_MSG_Template::generate_url_trigger( |
|
510 | + $sending_messenger, |
|
511 | + $message->messenger(), |
|
512 | + $message->context(), |
|
513 | + $message->message_type(), |
|
514 | + $registration, |
|
515 | + $message->GRP_ID() |
|
516 | + ); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
522 | + * @param EE_Message $message |
|
523 | + * @return string. |
|
524 | + */ |
|
525 | + public static function generate_browser_trigger(EE_Message $message) |
|
526 | + { |
|
527 | + $query_args = array( |
|
528 | + 'ee' => 'msg_browser_trigger', |
|
529 | + 'token' => $message->MSG_token() |
|
530 | + ); |
|
531 | + return apply_filters( |
|
532 | + 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
533 | + add_query_arg($query_args, site_url()), |
|
534 | + $message |
|
535 | + ); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
545 | + * @param EE_Message $message |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + public static function generate_error_display_trigger(EE_Message $message) |
|
549 | + { |
|
550 | + return apply_filters( |
|
551 | + 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
552 | + add_query_arg( |
|
553 | + array( |
|
554 | + 'ee' => 'msg_browser_error_trigger', |
|
555 | + 'token' => $message->MSG_token() |
|
556 | + ), |
|
557 | + site_url() |
|
558 | + ), |
|
559 | + $message |
|
560 | + ); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
570 | + * |
|
571 | + * @param string $sending_messenger The sending messenger slug. |
|
572 | + * @param string $generating_messenger The generating messenger slug. |
|
573 | + * @param string $context The context for the template. |
|
574 | + * @param string $message_type The message type slug |
|
575 | + * @param EE_Registration $registration |
|
576 | + * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
577 | + * @param integer $data_id The id to the EE_Base_Class for getting the data used by the trigger. |
|
578 | + * @return string The generated url. |
|
579 | + */ |
|
580 | + public static function generate_url_trigger( |
|
581 | + $sending_messenger, |
|
582 | + $generating_messenger, |
|
583 | + $context, |
|
584 | + $message_type, |
|
585 | + EE_Registration $registration, |
|
586 | + $message_template_group, |
|
587 | + $data_id = 0 |
|
588 | + ) { |
|
589 | + $query_args = array( |
|
590 | + 'ee' => 'msg_url_trigger', |
|
591 | + 'snd_msgr' => $sending_messenger, |
|
592 | + 'gen_msgr' => $generating_messenger, |
|
593 | + 'message_type' => $message_type, |
|
594 | + 'context' => $context, |
|
595 | + 'token' => $registration->reg_url_link(), |
|
596 | + 'GRP_ID' => $message_template_group, |
|
597 | + 'id' => $data_id |
|
598 | + ); |
|
599 | + $url = add_query_arg($query_args, get_home_url()); |
|
600 | + |
|
601 | + // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
602 | + $url = apply_filters( |
|
603 | + 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
604 | + $url, |
|
605 | + $sending_messenger, |
|
606 | + $generating_messenger, |
|
607 | + $context, |
|
608 | + $message_type, |
|
609 | + $registration, |
|
610 | + $message_template_group, |
|
611 | + $data_id |
|
612 | + ); |
|
613 | + return $url; |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Return the specific css for the action icon given. |
|
621 | + * |
|
622 | + * @since 4.9.0 |
|
623 | + * |
|
624 | + * @param string $type What action to return. |
|
625 | + * @return string |
|
626 | + */ |
|
627 | + public static function get_message_action_icon($type) |
|
628 | + { |
|
629 | + $action_icons = self::get_message_action_icons(); |
|
630 | + return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * This is used for retrieving the css classes used for the icons representing message actions. |
|
636 | + * |
|
637 | + * @since 4.9.0 |
|
638 | + * |
|
639 | + * @return array |
|
640 | + */ |
|
641 | + public static function get_message_action_icons() |
|
642 | + { |
|
643 | + return apply_filters( |
|
644 | + 'FHEE__EEH_MSG_Template__message_action_icons', |
|
645 | + array( |
|
646 | + 'view' => array( |
|
647 | + 'label' => __('View Message', 'event_espresso'), |
|
648 | + 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
649 | + ), |
|
650 | + 'error' => array( |
|
651 | + 'label' => __('View Error Message', 'event_espresso'), |
|
652 | + 'css_class' => 'dashicons dashicons-info', |
|
653 | + ), |
|
654 | + 'see_notifications_for' => array( |
|
655 | + 'label' => __('View Related Messages', 'event_espresso'), |
|
656 | + 'css_class' => 'dashicons dashicons-megaphone', |
|
657 | + ), |
|
658 | + 'generate_now' => array( |
|
659 | + 'label' => __('Generate the message now.', 'event_espresso'), |
|
660 | + 'css_class' => 'dashicons dashicons-admin-tools', |
|
661 | + ), |
|
662 | + 'send_now' => array( |
|
663 | + 'label' => __('Send Immediately', 'event_espresso'), |
|
664 | + 'css_class' => 'dashicons dashicons-controls-forward', |
|
665 | + ), |
|
666 | + 'queue_for_resending' => array( |
|
667 | + 'label' => __('Queue for Resending', 'event_espresso'), |
|
668 | + 'css_class' => 'dashicons dashicons-controls-repeat', |
|
669 | + ), |
|
670 | + 'view_transaction' => array( |
|
671 | + 'label' => __('View related Transaction', 'event_espresso'), |
|
672 | + 'css_class' => 'dashicons dashicons-cart', |
|
673 | + ) |
|
674 | + ) |
|
675 | + ); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * This returns the url for a given action related to EE_Message. |
|
681 | + * |
|
682 | + * @since 4.9.0 |
|
683 | + * |
|
684 | + * @param string $type What type of action to return the url for. |
|
685 | + * @param EE_Message $message Required for generating the correct url for some types. |
|
686 | + * @param array $query_params Any additional query params to be included with the generated url. |
|
687 | + * |
|
688 | + * @return string |
|
689 | + */ |
|
690 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
691 | + { |
|
692 | + $action_urls = self::get_message_action_urls($message, $query_params); |
|
693 | + return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * This returns all the current urls for EE_Message actions. |
|
700 | + * |
|
701 | + * @since 4.9.0 |
|
702 | + * |
|
703 | + * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
704 | + * @param array $query_params Any additional query_params to be included with the generated url. |
|
705 | + * |
|
706 | + * @return array |
|
707 | + */ |
|
708 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
709 | + { |
|
710 | + EE_Registry::instance()->load_helper('URL'); |
|
711 | + // if $message is not an instance of EE_Message then let's just do a dummy. |
|
712 | + $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
713 | + $action_urls = apply_filters( |
|
714 | + 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
715 | + array( |
|
716 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
717 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
718 | + 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
719 | + array_merge( |
|
720 | + array( |
|
721 | + 'page' => 'espresso_messages', |
|
722 | + 'action' => 'default', |
|
723 | + 'filterby' => 1, |
|
724 | + ), |
|
725 | + $query_params |
|
726 | + ), |
|
727 | + admin_url('admin.php') |
|
728 | + ), |
|
729 | + 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
730 | + array( |
|
731 | + 'page' => 'espresso_messages', |
|
732 | + 'action' => 'generate_now', |
|
733 | + 'MSG_ID' => $message->ID() |
|
734 | + ), |
|
735 | + admin_url('admin.php') |
|
736 | + ), |
|
737 | + 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
738 | + array( |
|
739 | + 'page' => 'espresso_messages', |
|
740 | + 'action' => 'send_now', |
|
741 | + 'MSG_ID' => $message->ID() |
|
742 | + ), |
|
743 | + admin_url('admin.php') |
|
744 | + ), |
|
745 | + 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
746 | + array( |
|
747 | + 'page' => 'espresso_messages', |
|
748 | + 'action' => 'queue_for_resending', |
|
749 | + 'MSG_ID' => $message->ID() |
|
750 | + ), |
|
751 | + admin_url('admin.php') |
|
752 | + ), |
|
753 | + ) |
|
754 | + ); |
|
755 | + if ( |
|
756 | + $message->TXN_ID() > 0 |
|
757 | + && EE_Registry::instance()->CAP->current_user_can( |
|
758 | + 'ee_read_transaction', |
|
759 | + 'espresso_transactions_default', |
|
760 | + $message->TXN_ID() |
|
761 | + ) |
|
762 | + ) { |
|
763 | + $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
764 | + array( |
|
765 | + 'page' => 'espresso_transactions', |
|
766 | + 'action' => 'view_transaction', |
|
767 | + 'TXN_ID' => $message->TXN_ID() |
|
768 | + ), |
|
769 | + admin_url('admin.php') |
|
770 | + ); |
|
771 | + } else { |
|
772 | + $action_urls['view_transaction'] = ''; |
|
773 | + } |
|
774 | + return $action_urls; |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
780 | + * |
|
781 | + * @since 4.9.0 |
|
782 | + * |
|
783 | + * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
784 | + * empty string is returned) |
|
785 | + * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
786 | + * @param array $query_params Any extra query params to include in the generated link. |
|
787 | + * |
|
788 | + * @return string |
|
789 | + */ |
|
790 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
791 | + { |
|
792 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
793 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
794 | + $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
795 | + |
|
796 | + if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
797 | + return ''; |
|
798 | + } |
|
799 | + |
|
800 | + $icon_css['css_class'] .= esc_attr( |
|
801 | + apply_filters( |
|
802 | + 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
803 | + ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
804 | + $type, |
|
805 | + $message, |
|
806 | + $query_params |
|
807 | + ) |
|
808 | + ); |
|
809 | + |
|
810 | + return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + |
|
815 | + |
|
816 | + |
|
817 | + /** |
|
818 | + * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
819 | + * |
|
820 | + * @since 4.9.0 |
|
821 | + * @return array |
|
822 | + */ |
|
823 | + public static function reg_status_to_message_type_array() |
|
824 | + { |
|
825 | + return (array) apply_filters( |
|
826 | + 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
827 | + array( |
|
828 | + EEM_Registration::status_id_approved => 'registration', |
|
829 | + EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
830 | + EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
831 | + EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
832 | + EEM_Registration::status_id_declined => 'declined_registration' |
|
833 | + ) |
|
834 | + ); |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
842 | + * match, then returns an empty string. |
|
843 | + * |
|
844 | + * @since 4.9.0 |
|
845 | + * @param $reg_status |
|
846 | + * @return string |
|
847 | + */ |
|
848 | + public static function convert_reg_status_to_message_type($reg_status) |
|
849 | + { |
|
850 | + $reg_status_array = self::reg_status_to_message_type_array(); |
|
851 | + return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
852 | + } |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
857 | + * |
|
858 | + * @since 4.9.0 |
|
859 | + * @return array |
|
860 | + */ |
|
861 | + public static function payment_status_to_message_type_array() |
|
862 | + { |
|
863 | + return (array) apply_filters( |
|
864 | + 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
865 | + array( |
|
866 | + EEM_Payment::status_id_approved => 'payment', |
|
867 | + EEM_Payment::status_id_pending => 'payment_pending', |
|
868 | + EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
869 | + EEM_Payment::status_id_declined => 'payment_declined', |
|
870 | + EEM_Payment::status_id_failed => 'payment_failed' |
|
871 | + ) |
|
872 | + ); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + |
|
878 | + /** |
|
879 | + * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
880 | + * an empty string is returned |
|
881 | + * |
|
882 | + * @since 4.9.0 |
|
883 | + * @param $payment_status |
|
884 | + * @return string |
|
885 | + */ |
|
886 | + public static function convert_payment_status_to_message_type($payment_status) |
|
887 | + { |
|
888 | + $payment_status_array = self::payment_status_to_message_type_array(); |
|
889 | + return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * This is used to retrieve the template pack for the given name. |
|
895 | + * |
|
896 | + * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
897 | + * |
|
898 | + * @return EE_Messages_Template_Pack |
|
899 | + */ |
|
900 | + public static function get_template_pack($template_pack_name) |
|
901 | + { |
|
902 | + if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
903 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
904 | + } |
|
905 | + |
|
906 | + // first see if in collection already |
|
907 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
908 | + |
|
909 | + if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
910 | + return $template_pack; |
|
911 | + } |
|
912 | + |
|
913 | + // nope...let's get it. |
|
914 | + // not set yet so let's attempt to get it. |
|
915 | + $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
916 | + ' ', |
|
917 | + '_', |
|
918 | + ucwords( |
|
919 | + str_replace('_', ' ', $template_pack_name) |
|
920 | + ) |
|
921 | + ); |
|
922 | + if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
923 | + return self::get_template_pack('default'); |
|
924 | + } else { |
|
925 | + $template_pack = new $pack_class_name(); |
|
926 | + self::$_template_pack_collection->add($template_pack); |
|
927 | + return $template_pack; |
|
928 | + } |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
936 | + * in it. |
|
937 | + * |
|
938 | + * @since 4.9.0 |
|
939 | + * |
|
940 | + * @return EE_Messages_Template_Pack_Collection |
|
941 | + */ |
|
942 | + public static function get_template_pack_collection() |
|
943 | + { |
|
944 | + $new_collection = false; |
|
945 | + if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
946 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
947 | + $new_collection = true; |
|
948 | + } |
|
949 | + |
|
950 | + // glob the defaults directory for messages |
|
951 | + $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
952 | + foreach ($templates as $template_path) { |
|
953 | + // grab folder name |
|
954 | + $template = basename($template_path); |
|
955 | + |
|
956 | + if (! $new_collection) { |
|
957 | + // already have it? |
|
958 | + if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
959 | + continue; |
|
960 | + } |
|
961 | + } |
|
962 | + |
|
963 | + // setup classname. |
|
964 | + $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
965 | + ' ', |
|
966 | + '_', |
|
967 | + ucwords( |
|
968 | + str_replace( |
|
969 | + '_', |
|
970 | + ' ', |
|
971 | + $template |
|
972 | + ) |
|
973 | + ) |
|
974 | + ); |
|
975 | + if (! class_exists($template_pack_class_name)) { |
|
976 | + continue; |
|
977 | + } |
|
978 | + self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
979 | + } |
|
980 | + |
|
981 | + /** |
|
982 | + * Filter for plugins to add in any additional template packs |
|
983 | + * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
984 | + */ |
|
985 | + $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
986 | + foreach ((array) $additional_template_packs as $template_pack) { |
|
987 | + if ( |
|
988 | + self::$_template_pack_collection->get_by_name( |
|
989 | + $template_pack->dbref |
|
990 | + ) instanceof EE_Messages_Template_Pack |
|
991 | + ) { |
|
992 | + continue; |
|
993 | + } |
|
994 | + self::$_template_pack_collection->add($template_pack); |
|
995 | + } |
|
996 | + return self::$_template_pack_collection; |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * This is a wrapper for the protected _create_new_templates function |
|
1003 | + * |
|
1004 | + * @param string $messenger_name |
|
1005 | + * @param string $message_type_name message type that the templates are being created for |
|
1006 | + * @param int $GRP_ID |
|
1007 | + * @param bool $global |
|
1008 | + * @return array |
|
1009 | + * @throws \EE_Error |
|
1010 | + */ |
|
1011 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
1012 | + { |
|
1013 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
1014 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1015 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
1016 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
1017 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
1018 | + return array(); |
|
1019 | + } |
|
1020 | + // whew made it this far! Okay, let's go ahead and create the templates then |
|
1021 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * @param \EE_messenger $messenger |
|
1028 | + * @param \EE_message_type $message_type |
|
1029 | + * @param $GRP_ID |
|
1030 | + * @param $global |
|
1031 | + * @return array|mixed |
|
1032 | + */ |
|
1033 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
1034 | + { |
|
1035 | + // if we're creating a custom template then we don't need to use the defaults class |
|
1036 | + if (! $global) { |
|
1037 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
1038 | + } |
|
1039 | + /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
1040 | + $Message_Template_Defaults = EE_Registry::factory( |
|
1041 | + 'EE_Messages_Template_Defaults', |
|
1042 | + array( $messenger, $message_type, $GRP_ID ) |
|
1043 | + ); |
|
1044 | + // generate templates |
|
1045 | + $success = $Message_Template_Defaults->create_new_templates(); |
|
1046 | + |
|
1047 | + // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
1048 | + // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
1049 | + // attempts. |
|
1050 | + if (! $success) { |
|
1051 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
1052 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1053 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
1054 | + } |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * $success is in an array in the following format |
|
1058 | + * array( |
|
1059 | + * 'GRP_ID' => $new_grp_id, |
|
1060 | + * 'MTP_context' => $first_context_in_new_templates, |
|
1061 | + * ) |
|
1062 | + */ |
|
1063 | + return $success; |
|
1064 | + } |
|
1065 | + |
|
1066 | + |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * This creates a custom template using the incoming GRP_ID |
|
1070 | + * |
|
1071 | + * @param \EE_messenger $messenger |
|
1072 | + * @param \EE_message_type $message_type |
|
1073 | + * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
1074 | + * @return array $success This will be an array in the format: |
|
1075 | + * array( |
|
1076 | + * 'GRP_ID' => $new_grp_id, |
|
1077 | + * 'MTP_context' => $first_context_in_created_template |
|
1078 | + * ) |
|
1079 | + * @access private |
|
1080 | + */ |
|
1081 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
1082 | + { |
|
1083 | + // defaults |
|
1084 | + $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
1085 | + // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
1086 | + $Message_Template_Group = empty($GRP_ID) |
|
1087 | + ? EEM_Message_Template_Group::instance()->get_one( |
|
1088 | + array( |
|
1089 | + array( |
|
1090 | + 'MTP_messenger' => $messenger->name, |
|
1091 | + 'MTP_message_type' => $message_type->name, |
|
1092 | + 'MTP_is_global' => true |
|
1093 | + ) |
|
1094 | + ) |
|
1095 | + ) |
|
1096 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
1097 | + // if we don't have a mtg at this point then we need to bail. |
|
1098 | + if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
1099 | + EE_Error::add_error( |
|
1100 | + sprintf( |
|
1101 | + __( |
|
1102 | + 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
1103 | + 'event_espresso' |
|
1104 | + ), |
|
1105 | + $GRP_ID |
|
1106 | + ), |
|
1107 | + __FILE__, |
|
1108 | + __FUNCTION__, |
|
1109 | + __LINE__ |
|
1110 | + ); |
|
1111 | + return $success; |
|
1112 | + } |
|
1113 | + // let's get all the related message_template objects for this group. |
|
1114 | + $message_templates = $Message_Template_Group->message_templates(); |
|
1115 | + // now we have what we need to setup the new template |
|
1116 | + $new_mtg = clone $Message_Template_Group; |
|
1117 | + $new_mtg->set('GRP_ID', 0); |
|
1118 | + $new_mtg->set('MTP_is_global', false); |
|
1119 | + $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName']) |
|
1120 | + ? $_POST['templateName'] |
|
1121 | + : __( |
|
1122 | + 'New Custom Template', |
|
1123 | + 'event_espresso' |
|
1124 | + ); |
|
1125 | + $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription']) |
|
1126 | + ? $_POST['templateDescription'] |
|
1127 | + : sprintf( |
|
1128 | + __( |
|
1129 | + 'This is a custom template that was created for the %s messenger and %s message type.', |
|
1130 | + 'event_espresso' |
|
1131 | + ), |
|
1132 | + $new_mtg->messenger_obj()->label['singular'], |
|
1133 | + $new_mtg->message_type_obj()->label['singular'] |
|
1134 | + ); |
|
1135 | + $new_mtg->set('MTP_name', $template_name); |
|
1136 | + $new_mtg->set('MTP_description', $template_description); |
|
1137 | + // remove ALL relations on this template group so they don't get saved! |
|
1138 | + $new_mtg->_remove_relations('Message_Template'); |
|
1139 | + $new_mtg->save(); |
|
1140 | + $success['GRP_ID'] = $new_mtg->ID(); |
|
1141 | + $success['template_name'] = $template_name; |
|
1142 | + // add new message templates and add relation to. |
|
1143 | + foreach ($message_templates as $message_template) { |
|
1144 | + if (! $message_template instanceof EE_Message_Template) { |
|
1145 | + continue; |
|
1146 | + } |
|
1147 | + $new_message_template = clone $message_template; |
|
1148 | + $new_message_template->set('MTP_ID', 0); |
|
1149 | + $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
1150 | + $new_message_template->save(); |
|
1151 | + if (empty($success['MTP_context'])) { |
|
1152 | + $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
1153 | + } |
|
1154 | + } |
|
1155 | + return $success; |
|
1156 | + } |
|
1157 | + |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * message_type_has_active_templates_for_messenger |
|
1162 | + * |
|
1163 | + * @param \EE_messenger $messenger |
|
1164 | + * @param \EE_message_type $message_type |
|
1165 | + * @param bool $global |
|
1166 | + * @return bool |
|
1167 | + */ |
|
1168 | + public static function message_type_has_active_templates_for_messenger( |
|
1169 | + EE_messenger $messenger, |
|
1170 | + EE_message_type $message_type, |
|
1171 | + $global = false |
|
1172 | + ) { |
|
1173 | + // is given message_type valid for given messenger (if this is not a global save) |
|
1174 | + if ($global) { |
|
1175 | + return true; |
|
1176 | + } |
|
1177 | + $active_templates = EEM_Message_Template_Group::instance()->count( |
|
1178 | + array( |
|
1179 | + array( |
|
1180 | + 'MTP_is_active' => true, |
|
1181 | + 'MTP_messenger' => $messenger->name, |
|
1182 | + 'MTP_message_type' => $message_type->name |
|
1183 | + ) |
|
1184 | + ) |
|
1185 | + ); |
|
1186 | + if ($active_templates > 0) { |
|
1187 | + return true; |
|
1188 | + } |
|
1189 | + EE_Error::add_error( |
|
1190 | + sprintf( |
|
1191 | + __( |
|
1192 | + 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
1193 | + 'event_espresso' |
|
1194 | + ), |
|
1195 | + $message_type->name, |
|
1196 | + $messenger->name |
|
1197 | + ), |
|
1198 | + __FILE__, |
|
1199 | + __FUNCTION__, |
|
1200 | + __LINE__ |
|
1201 | + ); |
|
1202 | + return false; |
|
1203 | + } |
|
1204 | + |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * get_fields |
|
1209 | + * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
1210 | + * |
|
1211 | + * @param string $messenger_name name of EE_messenger |
|
1212 | + * @param string $message_type_name name of EE_message_type |
|
1213 | + * @return array |
|
1214 | + */ |
|
1215 | + public static function get_fields($messenger_name, $message_type_name) |
|
1216 | + { |
|
1217 | + $template_fields = array(); |
|
1218 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
1219 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1220 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
1221 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
1222 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
1223 | + return array(); |
|
1224 | + } |
|
1225 | + |
|
1226 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
1227 | + |
|
1228 | + // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
1229 | + foreach ($message_type->get_contexts() as $context => $details) { |
|
1230 | + foreach ($messenger->get_template_fields() as $field => $value) { |
|
1231 | + if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
1232 | + continue; |
|
1233 | + } |
|
1234 | + $template_fields[ $context ][ $field ] = $value; |
|
1235 | + } |
|
1236 | + } |
|
1237 | + if (empty($template_fields)) { |
|
1238 | + EE_Error::add_error( |
|
1239 | + __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
1240 | + __FILE__, |
|
1241 | + __FUNCTION__, |
|
1242 | + __LINE__ |
|
1243 | + ); |
|
1244 | + return array(); |
|
1245 | + } |
|
1246 | + return $template_fields; |
|
1247 | + } |
|
1248 | 1248 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
90 | 90 | |
91 | - if (! $new_message_template_group) { |
|
91 | + if ( ! $new_message_template_group) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | $templates[] = $new_message_template_group; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ) |
120 | 120 | ) |
121 | 121 | ) |
122 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
122 | + : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); |
|
123 | 123 | |
124 | 124 | return $count > 0; |
125 | 125 | } |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public static function update_to_active($messenger_names, $message_type_names) |
139 | 139 | { |
140 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
141 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
140 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names); |
|
141 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names); |
|
142 | 142 | return EEM_Message_Template_Group::instance()->update( |
143 | - array( 'MTP_is_active' => 1 ), |
|
143 | + array('MTP_is_active' => 1), |
|
144 | 144 | array( |
145 | 145 | array( |
146 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
147 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
146 | + 'MTP_messenger' => array('IN', $messenger_names), |
|
147 | + 'MTP_message_type' => array('IN', $message_type_names) |
|
148 | 148 | ) |
149 | 149 | ) |
150 | 150 | ); |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | $messenger = $message_resource_manager->get_messenger($messenger); |
231 | 231 | |
232 | 232 | // if messenger isn't a EE_messenger resource then bail. |
233 | - if (! $messenger instanceof EE_messenger) { |
|
233 | + if ( ! $messenger instanceof EE_messenger) { |
|
234 | 234 | return array(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | // validate class for getting our list of shortcodes |
238 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
239 | - if (! class_exists($classname)) { |
|
238 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
239 | + if ( ! class_exists($classname)) { |
|
240 | 240 | $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
241 | 241 | $msg[] = sprintf( |
242 | 242 | __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
@@ -252,44 +252,44 @@ discard block |
||
252 | 252 | // let's make sure we're only getting the shortcode part of the validators |
253 | 253 | $shortcodes = array(); |
254 | 254 | foreach ($valid_shortcodes as $field => $validators) { |
255 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
255 | + $shortcodes[$field] = $validators['shortcodes']; |
|
256 | 256 | } |
257 | 257 | $valid_shortcodes = $shortcodes; |
258 | 258 | |
259 | 259 | // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
260 | - if (! empty($fields)) { |
|
260 | + if ( ! empty($fields)) { |
|
261 | 261 | $specified_shortcodes = array(); |
262 | 262 | foreach ($fields as $field) { |
263 | - if (isset($valid_shortcodes[ $field ])) { |
|
264 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
263 | + if (isset($valid_shortcodes[$field])) { |
|
264 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | $valid_shortcodes = $specified_shortcodes; |
268 | 268 | } |
269 | 269 | |
270 | 270 | // if not merged then let's replace the fields with the localized fields |
271 | - if (! $merged) { |
|
271 | + if ( ! $merged) { |
|
272 | 272 | // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
273 | 273 | $field_settings = $messenger->get_template_fields(); |
274 | 274 | $localized = array(); |
275 | 275 | foreach ($valid_shortcodes as $field => $shortcodes) { |
276 | 276 | // get localized field label |
277 | - if (isset($field_settings[ $field ])) { |
|
277 | + if (isset($field_settings[$field])) { |
|
278 | 278 | // possible that this is used as a main field. |
279 | - if (empty($field_settings[ $field ])) { |
|
280 | - if (isset($field_settings['extra'][ $field ])) { |
|
281 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
279 | + if (empty($field_settings[$field])) { |
|
280 | + if (isset($field_settings['extra'][$field])) { |
|
281 | + $_field = $field_settings['extra'][$field]['main']['label']; |
|
282 | 282 | } else { |
283 | 283 | $_field = $field; |
284 | 284 | } |
285 | 285 | } else { |
286 | - $_field = $field_settings[ $field ]['label']; |
|
286 | + $_field = $field_settings[$field]['label']; |
|
287 | 287 | } |
288 | 288 | } elseif (isset($field_settings['extra'])) { |
289 | 289 | // loop through extra "main fields" and see if any of their children have our field |
290 | 290 | foreach ($field_settings['extra'] as $main_field => $fields) { |
291 | - if (isset($fields[ $field ])) { |
|
292 | - $_field = $fields[ $field ]['label']; |
|
291 | + if (isset($fields[$field])) { |
|
292 | + $_field = $fields[$field]['label']; |
|
293 | 293 | } else { |
294 | 294 | $_field = $field; |
295 | 295 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $_field = $field; |
299 | 299 | } |
300 | 300 | if (isset($_field)) { |
301 | - $localized[ (string) $_field ] = $shortcodes; |
|
301 | + $localized[(string) $_field] = $shortcodes; |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | $valid_shortcodes = $localized; |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | $merged_codes = array(); |
310 | 310 | foreach ($valid_shortcodes as $field => $shortcode) { |
311 | 311 | foreach ($shortcode as $code => $label) { |
312 | - if (isset($merged_codes[ $code ])) { |
|
312 | + if (isset($merged_codes[$code])) { |
|
313 | 313 | continue; |
314 | 314 | } else { |
315 | - $merged_codes[ $code ] = $label; |
|
315 | + $merged_codes[$code] = $label; |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | } |
@@ -462,12 +462,12 @@ discard block |
||
462 | 462 | $sending_messenger = '' |
463 | 463 | ) { |
464 | 464 | // first determine if the url can be to the EE_Message object. |
465 | - if (! $message_type->always_generate()) { |
|
465 | + if ( ! $message_type->always_generate()) { |
|
466 | 466 | return EEH_MSG_Template::generate_browser_trigger($message); |
467 | 467 | } |
468 | 468 | |
469 | 469 | // if $registration object is not valid then exit early because there's nothing that can be generated. |
470 | - if (! $registration instanceof EE_Registration) { |
|
470 | + if ( ! $registration instanceof EE_Registration) { |
|
471 | 471 | throw new EE_Error( |
472 | 472 | __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
473 | 473 | ); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | |
476 | 476 | // validate given context |
477 | 477 | $contexts = $message_type->get_contexts(); |
478 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
478 | + if ($message->context() !== '' && ! isset($contexts[$message->context()])) { |
|
479 | 479 | throw new EE_Error( |
480 | 480 | sprintf( |
481 | 481 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -486,11 +486,11 @@ discard block |
||
486 | 486 | } |
487 | 487 | |
488 | 488 | // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
489 | - if (! empty($sending_messenger)) { |
|
489 | + if ( ! empty($sending_messenger)) { |
|
490 | 490 | $with_messengers = $message_type->with_messengers(); |
491 | 491 | if ( |
492 | - ! isset($with_messengers[ $message->messenger() ]) |
|
493 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
492 | + ! isset($with_messengers[$message->messenger()]) |
|
493 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()]) |
|
494 | 494 | ) { |
495 | 495 | throw new EE_Error( |
496 | 496 | sprintf( |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | public static function get_message_action_icon($type) |
628 | 628 | { |
629 | 629 | $action_icons = self::get_message_action_icons(); |
630 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
630 | + return isset($action_icons[$type]) ? $action_icons[$type] : ''; |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
691 | 691 | { |
692 | 692 | $action_urls = self::get_message_action_urls($message, $query_params); |
693 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
693 | + return isset($action_urls[$type]) ? $action_urls[$type] : ''; |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | EE_Registry::instance()->load_helper('URL'); |
711 | 711 | // if $message is not an instance of EE_Message then let's just do a dummy. |
712 | 712 | $message = empty($message) ? EE_Message_Factory::create() : $message; |
713 | - $action_urls = apply_filters( |
|
713 | + $action_urls = apply_filters( |
|
714 | 714 | 'FHEE__EEH_MSG_Template__get_message_action_url', |
715 | 715 | array( |
716 | 716 | 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | { |
792 | 792 | $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
793 | 793 | $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
794 | - $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
794 | + $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : ''; |
|
795 | 795 | |
796 | 796 | if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
797 | 797 | return ''; |
@@ -800,14 +800,14 @@ discard block |
||
800 | 800 | $icon_css['css_class'] .= esc_attr( |
801 | 801 | apply_filters( |
802 | 802 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
803 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
803 | + ' js-ee-message-action-link ee-message-action-link-'.$type, |
|
804 | 804 | $type, |
805 | 805 | $message, |
806 | 806 | $query_params |
807 | 807 | ) |
808 | 808 | ); |
809 | 809 | |
810 | - return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
810 | + return '<a href="'.$url.'"'.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>'; |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | public static function convert_reg_status_to_message_type($reg_status) |
849 | 849 | { |
850 | 850 | $reg_status_array = self::reg_status_to_message_type_array(); |
851 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
851 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : ''; |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | public static function convert_payment_status_to_message_type($payment_status) |
887 | 887 | { |
888 | 888 | $payment_status_array = self::payment_status_to_message_type_array(); |
889 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
889 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : ''; |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | */ |
900 | 900 | public static function get_template_pack($template_pack_name) |
901 | 901 | { |
902 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
902 | + if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
903 | 903 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
904 | 904 | } |
905 | 905 | |
@@ -912,14 +912,14 @@ discard block |
||
912 | 912 | |
913 | 913 | // nope...let's get it. |
914 | 914 | // not set yet so let's attempt to get it. |
915 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
915 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
916 | 916 | ' ', |
917 | 917 | '_', |
918 | 918 | ucwords( |
919 | 919 | str_replace('_', ' ', $template_pack_name) |
920 | 920 | ) |
921 | 921 | ); |
922 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
922 | + if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
923 | 923 | return self::get_template_pack('default'); |
924 | 924 | } else { |
925 | 925 | $template_pack = new $pack_class_name(); |
@@ -942,18 +942,18 @@ discard block |
||
942 | 942 | public static function get_template_pack_collection() |
943 | 943 | { |
944 | 944 | $new_collection = false; |
945 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
945 | + if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
946 | 946 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
947 | 947 | $new_collection = true; |
948 | 948 | } |
949 | 949 | |
950 | 950 | // glob the defaults directory for messages |
951 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
951 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR); |
|
952 | 952 | foreach ($templates as $template_path) { |
953 | 953 | // grab folder name |
954 | 954 | $template = basename($template_path); |
955 | 955 | |
956 | - if (! $new_collection) { |
|
956 | + if ( ! $new_collection) { |
|
957 | 957 | // already have it? |
958 | 958 | if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
959 | 959 | continue; |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | } |
962 | 962 | |
963 | 963 | // setup classname. |
964 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
964 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
965 | 965 | ' ', |
966 | 966 | '_', |
967 | 967 | ucwords( |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | ) |
973 | 973 | ) |
974 | 974 | ); |
975 | - if (! class_exists($template_pack_class_name)) { |
|
975 | + if ( ! class_exists($template_pack_class_name)) { |
|
976 | 976 | continue; |
977 | 977 | } |
978 | 978 | self::$_template_pack_collection->add(new $template_pack_class_name()); |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
1015 | 1015 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
1016 | 1016 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
1017 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
1017 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
1018 | 1018 | return array(); |
1019 | 1019 | } |
1020 | 1020 | // whew made it this far! Okay, let's go ahead and create the templates then |
@@ -1033,13 +1033,13 @@ discard block |
||
1033 | 1033 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
1034 | 1034 | { |
1035 | 1035 | // if we're creating a custom template then we don't need to use the defaults class |
1036 | - if (! $global) { |
|
1036 | + if ( ! $global) { |
|
1037 | 1037 | return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
1038 | 1038 | } |
1039 | 1039 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
1040 | 1040 | $Message_Template_Defaults = EE_Registry::factory( |
1041 | 1041 | 'EE_Messages_Template_Defaults', |
1042 | - array( $messenger, $message_type, $GRP_ID ) |
|
1042 | + array($messenger, $message_type, $GRP_ID) |
|
1043 | 1043 | ); |
1044 | 1044 | // generate templates |
1045 | 1045 | $success = $Message_Template_Defaults->create_new_templates(); |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
1048 | 1048 | // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
1049 | 1049 | // attempts. |
1050 | - if (! $success) { |
|
1050 | + if ( ! $success) { |
|
1051 | 1051 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
1052 | 1052 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
1053 | 1053 | $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
1082 | 1082 | { |
1083 | 1083 | // defaults |
1084 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
1084 | + $success = array('GRP_ID' => null, 'MTP_context' => ''); |
|
1085 | 1085 | // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
1086 | 1086 | $Message_Template_Group = empty($GRP_ID) |
1087 | 1087 | ? EEM_Message_Template_Group::instance()->get_one( |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | ) |
1096 | 1096 | : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
1097 | 1097 | // if we don't have a mtg at this point then we need to bail. |
1098 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
1098 | + if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
1099 | 1099 | EE_Error::add_error( |
1100 | 1100 | sprintf( |
1101 | 1101 | __( |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | $success['template_name'] = $template_name; |
1142 | 1142 | // add new message templates and add relation to. |
1143 | 1143 | foreach ($message_templates as $message_template) { |
1144 | - if (! $message_template instanceof EE_Message_Template) { |
|
1144 | + if ( ! $message_template instanceof EE_Message_Template) { |
|
1145 | 1145 | continue; |
1146 | 1146 | } |
1147 | 1147 | $new_message_template = clone $message_template; |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
1220 | 1220 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
1221 | 1221 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
1222 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
1222 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
1223 | 1223 | return array(); |
1224 | 1224 | } |
1225 | 1225 | |
@@ -1231,7 +1231,7 @@ discard block |
||
1231 | 1231 | if (in_array($field, $excluded_fields_for_messenger, true)) { |
1232 | 1232 | continue; |
1233 | 1233 | } |
1234 | - $template_fields[ $context ][ $field ] = $value; |
|
1234 | + $template_fields[$context][$field] = $value; |
|
1235 | 1235 | } |
1236 | 1236 | } |
1237 | 1237 | if (empty($template_fields)) { |