@@ -3,16 +3,16 @@ |
||
| 3 | 3 | |
| 4 | 4 | class EE_DB_Only_Float_Field extends EE_DB_Only_Field_Base |
| 5 | 5 | { |
| 6 | - /** |
|
| 7 | - * @param string $table_column |
|
| 8 | - * @param string $nicename |
|
| 9 | - * @param bool $nullable |
|
| 10 | - * @param null $default_value |
|
| 11 | - */ |
|
| 12 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 13 | - { |
|
| 14 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 15 | - $this->setSchemaType('number'); |
|
| 16 | - } |
|
| 6 | + /** |
|
| 7 | + * @param string $table_column |
|
| 8 | + * @param string $nicename |
|
| 9 | + * @param bool $nullable |
|
| 10 | + * @param null $default_value |
|
| 11 | + */ |
|
| 12 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 13 | + { |
|
| 14 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 15 | + $this->setSchemaType('number'); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | 18 | } |
@@ -4,27 +4,27 @@ |
||
| 4 | 4 | class EE_Primary_Key_Int_Field extends EE_Primary_Key_Field_Base |
| 5 | 5 | { |
| 6 | 6 | |
| 7 | - public function __construct($table_column, $nicename) |
|
| 8 | - { |
|
| 9 | - parent::__construct($table_column, $nicename, 0); |
|
| 10 | - $this->setSchemaType('integer'); |
|
| 11 | - } |
|
| 7 | + public function __construct($table_column, $nicename) |
|
| 8 | + { |
|
| 9 | + parent::__construct($table_column, $nicename, 0); |
|
| 10 | + $this->setSchemaType('integer'); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 14 | - { |
|
| 15 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 16 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 17 | - } |
|
| 18 | - return absint($value_inputted_for_field_on_model_object); |
|
| 19 | - } |
|
| 13 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 14 | + { |
|
| 15 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 16 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 17 | + } |
|
| 18 | + return absint($value_inputted_for_field_on_model_object); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 22 | - { |
|
| 23 | - return intval($value_found_in_db_for_model_object); |
|
| 24 | - } |
|
| 21 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 22 | + { |
|
| 23 | + return intval($value_found_in_db_for_model_object); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - function is_auto_increment() |
|
| 27 | - { |
|
| 28 | - return true; |
|
| 29 | - } |
|
| 26 | + function is_auto_increment() |
|
| 27 | + { |
|
| 28 | + return true; |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -4,6 +4,9 @@ |
||
| 4 | 4 | class EE_Primary_Key_Int_Field extends EE_Primary_Key_Field_Base |
| 5 | 5 | { |
| 6 | 6 | |
| 7 | + /** |
|
| 8 | + * @param string $table_column |
|
| 9 | + */ |
|
| 7 | 10 | public function __construct($table_column, $nicename) |
| 8 | 11 | { |
| 9 | 12 | parent::__construct($table_column, $nicename, 0); |
@@ -12,131 +12,131 @@ |
||
| 12 | 12 | class EE_Enum_Text_Field extends EE_Text_Field_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var array $_allowed_enum_values |
|
| 17 | - */ |
|
| 18 | - public $_allowed_enum_values; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @param string $table_column |
|
| 22 | - * @param string $nice_name |
|
| 23 | - * @param boolean $nullable |
|
| 24 | - * @param mixed $default_value |
|
| 25 | - * @param array $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed |
|
| 26 | - */ |
|
| 27 | - function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 28 | - { |
|
| 29 | - $this->_allowed_enum_values = $allowed_enum_values; |
|
| 30 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 31 | - $this->setSchemaType('object'); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Returns the list of allowed enum options, but filterable. |
|
| 38 | - * This is used internally |
|
| 39 | - * |
|
| 40 | - * @return array |
|
| 41 | - */ |
|
| 42 | - protected function _allowed_enum_values() |
|
| 43 | - { |
|
| 44 | - return apply_filters( |
|
| 45 | - 'FHEE__EE_Enum_Text_Field___allowed_enum_options', |
|
| 46 | - $this->_allowed_enum_values, |
|
| 47 | - $this |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * When setting, just verify that the value being used matches what we've defined as allowable enum values. |
|
| 55 | - * If not, throw an error (but if WP_DEBUG is false, just set the value to default). |
|
| 56 | - * |
|
| 57 | - * @param string $value_inputted_for_field_on_model_object |
|
| 58 | - * @return string |
|
| 59 | - * @throws EE_Error |
|
| 60 | - */ |
|
| 61 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 62 | - { |
|
| 63 | - if ( |
|
| 64 | - $value_inputted_for_field_on_model_object !== null |
|
| 65 | - && ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values()) |
|
| 66 | - ) { |
|
| 67 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 68 | - $msg = sprintf( |
|
| 69 | - __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'), |
|
| 70 | - $value_inputted_for_field_on_model_object, |
|
| 71 | - $this->_name |
|
| 72 | - ); |
|
| 73 | - $msg2 = sprintf( |
|
| 74 | - __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'), |
|
| 75 | - $this->_name, |
|
| 76 | - implode(', ', array_keys($this->_allowed_enum_values())), |
|
| 77 | - $value_inputted_for_field_on_model_object |
|
| 78 | - ); |
|
| 79 | - EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__); |
|
| 80 | - } |
|
| 81 | - return $this->get_default_value(); |
|
| 82 | - } |
|
| 83 | - return $value_inputted_for_field_on_model_object; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Gets the pretty version of the enum's value. |
|
| 89 | - * |
|
| 90 | - * @param int |string $value_on_field_to_be_outputted |
|
| 91 | - * @param null $schema |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 95 | - { |
|
| 96 | - $options = $this->_allowed_enum_values(); |
|
| 97 | - if (isset($options[$value_on_field_to_be_outputted])) { |
|
| 98 | - return $options[$value_on_field_to_be_outputted]; |
|
| 99 | - } else { |
|
| 100 | - return $value_on_field_to_be_outputted; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live |
|
| 108 | - * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY |
|
| 109 | - * when we're receiving USER input from prepare_for_set() that we enforce the enum options. |
|
| 110 | - * |
|
| 111 | - * @param mixed $value_in_db |
|
| 112 | - * @return mixed |
|
| 113 | - */ |
|
| 114 | - public function prepare_for_set_from_db($value_in_db) |
|
| 115 | - { |
|
| 116 | - return $value_in_db; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - public function getSchemaProperties() |
|
| 121 | - { |
|
| 122 | - return array( |
|
| 123 | - 'raw' => array( |
|
| 124 | - 'description' => sprintf( |
|
| 125 | - __('%s - the value in the database.', 'event_espresso'), |
|
| 126 | - $this->get_nicename() |
|
| 127 | - ), |
|
| 128 | - 'type' => 'string', |
|
| 129 | - 'enum' => array_keys($this->_allowed_enum_values) |
|
| 130 | - ), |
|
| 131 | - 'pretty' => array( |
|
| 132 | - 'description' => sprintf( |
|
| 133 | - __('%s - the value for display.', 'event_espresso'), |
|
| 134 | - $this->get_nicename() |
|
| 135 | - ), |
|
| 136 | - 'type' => 'string', |
|
| 137 | - 'enum' => array_values($this->_allowed_enum_values), |
|
| 138 | - 'read_only' => true |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - } |
|
| 15 | + /** |
|
| 16 | + * @var array $_allowed_enum_values |
|
| 17 | + */ |
|
| 18 | + public $_allowed_enum_values; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @param string $table_column |
|
| 22 | + * @param string $nice_name |
|
| 23 | + * @param boolean $nullable |
|
| 24 | + * @param mixed $default_value |
|
| 25 | + * @param array $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed |
|
| 26 | + */ |
|
| 27 | + function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 28 | + { |
|
| 29 | + $this->_allowed_enum_values = $allowed_enum_values; |
|
| 30 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 31 | + $this->setSchemaType('object'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Returns the list of allowed enum options, but filterable. |
|
| 38 | + * This is used internally |
|
| 39 | + * |
|
| 40 | + * @return array |
|
| 41 | + */ |
|
| 42 | + protected function _allowed_enum_values() |
|
| 43 | + { |
|
| 44 | + return apply_filters( |
|
| 45 | + 'FHEE__EE_Enum_Text_Field___allowed_enum_options', |
|
| 46 | + $this->_allowed_enum_values, |
|
| 47 | + $this |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * When setting, just verify that the value being used matches what we've defined as allowable enum values. |
|
| 55 | + * If not, throw an error (but if WP_DEBUG is false, just set the value to default). |
|
| 56 | + * |
|
| 57 | + * @param string $value_inputted_for_field_on_model_object |
|
| 58 | + * @return string |
|
| 59 | + * @throws EE_Error |
|
| 60 | + */ |
|
| 61 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 62 | + { |
|
| 63 | + if ( |
|
| 64 | + $value_inputted_for_field_on_model_object !== null |
|
| 65 | + && ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values()) |
|
| 66 | + ) { |
|
| 67 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 68 | + $msg = sprintf( |
|
| 69 | + __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'), |
|
| 70 | + $value_inputted_for_field_on_model_object, |
|
| 71 | + $this->_name |
|
| 72 | + ); |
|
| 73 | + $msg2 = sprintf( |
|
| 74 | + __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'), |
|
| 75 | + $this->_name, |
|
| 76 | + implode(', ', array_keys($this->_allowed_enum_values())), |
|
| 77 | + $value_inputted_for_field_on_model_object |
|
| 78 | + ); |
|
| 79 | + EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__); |
|
| 80 | + } |
|
| 81 | + return $this->get_default_value(); |
|
| 82 | + } |
|
| 83 | + return $value_inputted_for_field_on_model_object; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Gets the pretty version of the enum's value. |
|
| 89 | + * |
|
| 90 | + * @param int |string $value_on_field_to_be_outputted |
|
| 91 | + * @param null $schema |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 95 | + { |
|
| 96 | + $options = $this->_allowed_enum_values(); |
|
| 97 | + if (isset($options[$value_on_field_to_be_outputted])) { |
|
| 98 | + return $options[$value_on_field_to_be_outputted]; |
|
| 99 | + } else { |
|
| 100 | + return $value_on_field_to_be_outputted; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live |
|
| 108 | + * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY |
|
| 109 | + * when we're receiving USER input from prepare_for_set() that we enforce the enum options. |
|
| 110 | + * |
|
| 111 | + * @param mixed $value_in_db |
|
| 112 | + * @return mixed |
|
| 113 | + */ |
|
| 114 | + public function prepare_for_set_from_db($value_in_db) |
|
| 115 | + { |
|
| 116 | + return $value_in_db; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + public function getSchemaProperties() |
|
| 121 | + { |
|
| 122 | + return array( |
|
| 123 | + 'raw' => array( |
|
| 124 | + 'description' => sprintf( |
|
| 125 | + __('%s - the value in the database.', 'event_espresso'), |
|
| 126 | + $this->get_nicename() |
|
| 127 | + ), |
|
| 128 | + 'type' => 'string', |
|
| 129 | + 'enum' => array_keys($this->_allowed_enum_values) |
|
| 130 | + ), |
|
| 131 | + 'pretty' => array( |
|
| 132 | + 'description' => sprintf( |
|
| 133 | + __('%s - the value for display.', 'event_espresso'), |
|
| 134 | + $this->get_nicename() |
|
| 135 | + ), |
|
| 136 | + 'type' => 'string', |
|
| 137 | + 'enum' => array_values($this->_allowed_enum_values), |
|
| 138 | + 'read_only' => true |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -15,57 +15,57 @@ |
||
| 15 | 15 | class EE_Full_HTML_Field extends EE_Text_Field_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param string $table_column |
|
| 20 | - * @param string $nicename |
|
| 21 | - * @param bool $nullable |
|
| 22 | - * @param null $default_value |
|
| 23 | - */ |
|
| 24 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 25 | - { |
|
| 26 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | - $this->setSchemaType('object'); |
|
| 28 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $table_column |
|
| 20 | + * @param string $nicename |
|
| 21 | + * @param bool $nullable |
|
| 22 | + * @param null $default_value |
|
| 23 | + */ |
|
| 24 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 25 | + { |
|
| 26 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | + $this->setSchemaType('object'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 33 | - * |
|
| 34 | - * @param type $value_on_field_to_be_outputted |
|
| 35 | - * @param type $schema |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 39 | - { |
|
| 40 | - if ($schema == 'form_input') { |
|
| 41 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 42 | - } elseif ($schema == 'no_wpautop') { |
|
| 43 | - return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 44 | - } else { |
|
| 45 | - return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + /** |
|
| 32 | + * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 33 | + * |
|
| 34 | + * @param type $value_on_field_to_be_outputted |
|
| 35 | + * @param type $schema |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 39 | + { |
|
| 40 | + if ($schema == 'form_input') { |
|
| 41 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 42 | + } elseif ($schema == 'no_wpautop') { |
|
| 43 | + return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 44 | + } else { |
|
| 45 | + return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | - public function getSchemaProperties() |
|
| 52 | - { |
|
| 53 | - return array( |
|
| 54 | - 'raw' => array( |
|
| 55 | - 'description' => sprintf( |
|
| 56 | - __('%s - the value in the database.', 'event_espresso'), |
|
| 57 | - $this->get_nicename() |
|
| 58 | - ), |
|
| 59 | - 'type' => 'string' |
|
| 60 | - ), |
|
| 61 | - 'rendered' => array( |
|
| 62 | - 'description' => sprintf( |
|
| 63 | - __('%s - transformed for display.', 'event_espresso'), |
|
| 64 | - $this->get_nicename() |
|
| 65 | - ), |
|
| 66 | - 'type' => 'string', |
|
| 67 | - 'readonly' => true |
|
| 68 | - ) |
|
| 69 | - ); |
|
| 70 | - } |
|
| 51 | + public function getSchemaProperties() |
|
| 52 | + { |
|
| 53 | + return array( |
|
| 54 | + 'raw' => array( |
|
| 55 | + 'description' => sprintf( |
|
| 56 | + __('%s - the value in the database.', 'event_espresso'), |
|
| 57 | + $this->get_nicename() |
|
| 58 | + ), |
|
| 59 | + 'type' => 'string' |
|
| 60 | + ), |
|
| 61 | + 'rendered' => array( |
|
| 62 | + 'description' => sprintf( |
|
| 63 | + __('%s - transformed for display.', 'event_espresso'), |
|
| 64 | + $this->get_nicename() |
|
| 65 | + ), |
|
| 66 | + 'type' => 'string', |
|
| 67 | + 'readonly' => true |
|
| 68 | + ) |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | * @param string $table_column |
| 14 | 14 | * @param string $nicename |
| 15 | 15 | * @param bool $nullable |
| 16 | - * @param null $default_value |
|
| 16 | + * @param string $default_value |
|
| 17 | 17 | */ |
| 18 | 18 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
| 19 | 19 | { |
@@ -17,482 +17,482 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class EE_Model_Relation_Base implements HasSchemaInterface |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
| 22 | - * |
|
| 23 | - * @var string eg Event, Question_Group, Registration |
|
| 24 | - */ |
|
| 25 | - private $_this_model_name; |
|
| 26 | - /** |
|
| 27 | - * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
| 28 | - * |
|
| 29 | - * @var string eg Event, Question_Group, Registration |
|
| 30 | - */ |
|
| 31 | - private $_other_model_name; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
| 35 | - * initiating model. |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $_timezone; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * If you try to delete "this_model", and there are related "other_models", |
|
| 43 | - * and this isn't null, then abandon the deletion and add this warning. |
|
| 44 | - * This effectively makes it impossible to delete "this_model" while there are |
|
| 45 | - * related "other_models" along this relation. |
|
| 46 | - * |
|
| 47 | - * @var string (internationalized) |
|
| 48 | - */ |
|
| 49 | - protected $_blocking_delete_error_message; |
|
| 50 | - |
|
| 51 | - protected $_blocking_delete = false; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Object representing the relationship between two models. This knows how to join the models, |
|
| 55 | - * get related models across the relation, and add-and-remove the relationships. |
|
| 56 | - * |
|
| 57 | - * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
| 58 | - * and add an error) the deletion of this model |
|
| 59 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
| 60 | - * default |
|
| 61 | - */ |
|
| 62 | - public function __construct($block_deletes, $blocking_delete_error_message) |
|
| 63 | - { |
|
| 64 | - $this->_blocking_delete = $block_deletes; |
|
| 65 | - $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $this_model_name |
|
| 71 | - * @param $other_model_name |
|
| 72 | - * @throws EE_Error |
|
| 73 | - */ |
|
| 74 | - public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
| 75 | - { |
|
| 76 | - $this->_this_model_name = $this_model_name; |
|
| 77 | - $this->_other_model_name = $other_model_name; |
|
| 78 | - if (is_string($this->_blocking_delete)) { |
|
| 79 | - throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
| 80 | - "event_espresso"), |
|
| 81 | - get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Gets the model where this relation is defined. |
|
| 88 | - * |
|
| 89 | - * @return EEM_Base |
|
| 90 | - */ |
|
| 91 | - public function get_this_model() |
|
| 92 | - { |
|
| 93 | - return $this->_get_model($this->_this_model_name); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets the model which this relation establishes the relation TO (ie, |
|
| 99 | - * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
| 100 | - * |
|
| 101 | - * @return EEM_Base |
|
| 102 | - */ |
|
| 103 | - public function get_other_model() |
|
| 104 | - { |
|
| 105 | - return $this->_get_model($this->_other_model_name); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Internally used by get_this_model() and get_other_model() |
|
| 111 | - * |
|
| 112 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
| 113 | - * @return EEM_Base |
|
| 114 | - */ |
|
| 115 | - protected function _get_model($model_name) |
|
| 116 | - { |
|
| 117 | - $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
| 118 | - $modelInstance->set_timezone($this->_timezone); |
|
| 119 | - return $modelInstance; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
| 125 | - * timezone set correctly. |
|
| 126 | - * |
|
| 127 | - * @param string $timezone timezone to set. |
|
| 128 | - */ |
|
| 129 | - public function set_timezone($timezone) |
|
| 130 | - { |
|
| 131 | - if ($timezone !== null) { |
|
| 132 | - $this->_timezone = $timezone; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param $other_table |
|
| 139 | - * @param $other_table_alias |
|
| 140 | - * @param $other_table_column |
|
| 141 | - * @param $this_table_alias |
|
| 142 | - * @param $this_table_join_column |
|
| 143 | - * @param string $extra_join_sql |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - protected function _left_join( |
|
| 147 | - $other_table, |
|
| 148 | - $other_table_alias, |
|
| 149 | - $other_table_column, |
|
| 150 | - $this_table_alias, |
|
| 151 | - $this_table_join_column, |
|
| 152 | - $extra_join_sql = '' |
|
| 153 | - ) { |
|
| 154 | - return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Gets all the model objects of type of other model related to $model_object, |
|
| 160 | - * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
| 161 | - * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
| 162 | - * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
| 163 | - * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
| 164 | - * |
|
| 165 | - * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
| 166 | - * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 167 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
| 168 | - * @return EE_Base_Class[] |
|
| 169 | - * @throws \EE_Error |
|
| 170 | - */ |
|
| 171 | - public function get_all_related( |
|
| 172 | - $model_object_or_id, |
|
| 173 | - $query_params = array(), |
|
| 174 | - $values_already_prepared_by_model_object = false |
|
| 175 | - ) { |
|
| 176 | - if ($values_already_prepared_by_model_object !== false) { |
|
| 177 | - EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', |
|
| 178 | - __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
| 179 | - '4.8.1'); |
|
| 180 | - } |
|
| 181 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
| 182 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
| 183 | - . "." |
|
| 184 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
| 185 | - $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
| 186 | - $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
| 187 | - return $this->get_other_model()->get_all($query_params); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
| 193 | - * |
|
| 194 | - * @param string $query_params |
|
| 195 | - * @return array |
|
| 196 | - */ |
|
| 197 | - protected function _disable_default_where_conditions_on_query_param($query_params) |
|
| 198 | - { |
|
| 199 | - if (! isset($query_params['default_where_conditions'])) { |
|
| 200 | - $query_params['default_where_conditions'] = 'none'; |
|
| 201 | - } |
|
| 202 | - return $query_params; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Deletes the related model objects which meet the query parameters. If no |
|
| 208 | - * parameters are specified, then all related model objects will be deleted. |
|
| 209 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
| 210 | - * model objects will only be soft-deleted. |
|
| 211 | - * |
|
| 212 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
| 213 | - * @param array $query_params |
|
| 214 | - * @return int of how many related models got deleted |
|
| 215 | - * @throws \EE_Error |
|
| 216 | - */ |
|
| 217 | - public function delete_all_related($model_object_or_id, $query_params = array()) |
|
| 218 | - { |
|
| 219 | - //for each thing we would delete, |
|
| 220 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
| 221 | - //determine if it's blocked by anything else before it can be deleted |
|
| 222 | - $deleted_count = 0; |
|
| 223 | - foreach ($related_model_objects as $related_model_object) { |
|
| 224 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
| 225 | - $model_object_or_id); |
|
| 226 | - /* @var $model_object_or_id EE_Base_Class */ |
|
| 227 | - if (! $delete_is_blocked) { |
|
| 228 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 229 | - $related_model_object->delete(); |
|
| 230 | - $deleted_count++; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - return $deleted_count; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Deletes the related model objects which meet the query parameters. If no |
|
| 239 | - * parameters are specified, then all related model objects will be deleted. |
|
| 240 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
| 241 | - * model objects will only be soft-deleted. |
|
| 242 | - * |
|
| 243 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
| 244 | - * @param array $query_params |
|
| 245 | - * @return int of how many related models got deleted |
|
| 246 | - * @throws \EE_Error |
|
| 247 | - */ |
|
| 248 | - public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
| 249 | - { |
|
| 250 | - //for each thing we would delete, |
|
| 251 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
| 252 | - //determine if it's blocked by anything else before it can be deleted |
|
| 253 | - $deleted_count = 0; |
|
| 254 | - foreach ($related_model_objects as $related_model_object) { |
|
| 255 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
| 256 | - $model_object_or_id); |
|
| 257 | - /* @var $model_object_or_id EE_Base_Class */ |
|
| 258 | - if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
| 259 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 260 | - $deleted_count++; |
|
| 261 | - if (! $delete_is_blocked) { |
|
| 262 | - $related_model_object->delete_permanently(); |
|
| 263 | - } else { |
|
| 264 | - //delete is blocked |
|
| 265 | - //brent and darren, in this case, wanted to just soft delete it then |
|
| 266 | - $related_model_object->delete(); |
|
| 267 | - } |
|
| 268 | - } else { |
|
| 269 | - //its not a soft-deletable thing anyways. do the normal logic. |
|
| 270 | - if (! $delete_is_blocked) { |
|
| 271 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 272 | - $related_model_object->delete(); |
|
| 273 | - $deleted_count++; |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - return $deleted_count; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * this just returns a model_object_id for incoming item that could be an object or id. |
|
| 283 | - * |
|
| 284 | - * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
| 285 | - * @throws EE_Error |
|
| 286 | - * @return int |
|
| 287 | - */ |
|
| 288 | - protected function _get_model_object_id($model_object_or_id) |
|
| 289 | - { |
|
| 290 | - $model_object_id = $model_object_or_id; |
|
| 291 | - if ($model_object_or_id instanceof EE_Base_Class) { |
|
| 292 | - $model_object_id = $model_object_or_id->ID(); |
|
| 293 | - } |
|
| 294 | - if (! $model_object_id) { |
|
| 295 | - throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
| 296 | - "event_espresso"), $this->get_other_model()->get_this_model_name(), |
|
| 297 | - $this->get_this_model()->get_this_model_name())); |
|
| 298 | - } |
|
| 299 | - return $model_object_id; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Gets the SQL string for performing the join between this model and the other model. |
|
| 305 | - * |
|
| 306 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
| 307 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
| 308 | - * other_model_primary_table.fk" etc |
|
| 309 | - */ |
|
| 310 | - abstract public function get_join_statement($model_relation_chain); |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
| 315 | - * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
| 316 | - * relationship only allows this model to be related to a single other model of this type) |
|
| 317 | - * |
|
| 318 | - * @param $this_obj_or_id |
|
| 319 | - * @param $other_obj_or_id |
|
| 320 | - * @param array $extra_join_model_fields_n_values |
|
| 321 | - * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
| 322 | - * $other_obj_or_id) |
|
| 323 | - */ |
|
| 324 | - abstract public function add_relation_to( |
|
| 325 | - $this_obj_or_id, |
|
| 326 | - $other_obj_or_id, |
|
| 327 | - $extra_join_model_fields_n_values = array() |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
| 333 | - * model objects |
|
| 334 | - * |
|
| 335 | - * @param $this_obj_or_id |
|
| 336 | - * @param $other_obj_or_id |
|
| 337 | - * @param array $where_query |
|
| 338 | - * @return bool |
|
| 339 | - */ |
|
| 340 | - abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Removes ALL relation instances for this relation obj |
|
| 345 | - * |
|
| 346 | - * @param EE_Base_Class|int $this_obj_or_id |
|
| 347 | - * @param array $where_query_param like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 348 | - * @return EE_Base_Class[] |
|
| 349 | - * @throws \EE_Error |
|
| 350 | - */ |
|
| 351 | - public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
| 352 | - { |
|
| 353 | - $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
| 354 | - $objs_removed = array(); |
|
| 355 | - foreach ($related_things as $related_thing) { |
|
| 356 | - $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
| 357 | - } |
|
| 358 | - return $objs_removed; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * If you aren't allowed to delete this model when there are related models across this |
|
| 364 | - * relation object, return true. Otherwise, if you can delete this model even though |
|
| 365 | - * related objects exist, returns false. |
|
| 366 | - * |
|
| 367 | - * @return boolean |
|
| 368 | - */ |
|
| 369 | - public function block_delete_if_related_models_exist() |
|
| 370 | - { |
|
| 371 | - return $this->_blocking_delete; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Gets the error message to show |
|
| 377 | - * |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - public function get_deletion_error_message() |
|
| 381 | - { |
|
| 382 | - if ($this->_blocking_delete_error_message) { |
|
| 383 | - return $this->_blocking_delete_error_message; |
|
| 384 | - } else { |
|
| 20 | + /** |
|
| 21 | + * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
| 22 | + * |
|
| 23 | + * @var string eg Event, Question_Group, Registration |
|
| 24 | + */ |
|
| 25 | + private $_this_model_name; |
|
| 26 | + /** |
|
| 27 | + * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
| 28 | + * |
|
| 29 | + * @var string eg Event, Question_Group, Registration |
|
| 30 | + */ |
|
| 31 | + private $_other_model_name; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
| 35 | + * initiating model. |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $_timezone; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * If you try to delete "this_model", and there are related "other_models", |
|
| 43 | + * and this isn't null, then abandon the deletion and add this warning. |
|
| 44 | + * This effectively makes it impossible to delete "this_model" while there are |
|
| 45 | + * related "other_models" along this relation. |
|
| 46 | + * |
|
| 47 | + * @var string (internationalized) |
|
| 48 | + */ |
|
| 49 | + protected $_blocking_delete_error_message; |
|
| 50 | + |
|
| 51 | + protected $_blocking_delete = false; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Object representing the relationship between two models. This knows how to join the models, |
|
| 55 | + * get related models across the relation, and add-and-remove the relationships. |
|
| 56 | + * |
|
| 57 | + * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
| 58 | + * and add an error) the deletion of this model |
|
| 59 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
| 60 | + * default |
|
| 61 | + */ |
|
| 62 | + public function __construct($block_deletes, $blocking_delete_error_message) |
|
| 63 | + { |
|
| 64 | + $this->_blocking_delete = $block_deletes; |
|
| 65 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $this_model_name |
|
| 71 | + * @param $other_model_name |
|
| 72 | + * @throws EE_Error |
|
| 73 | + */ |
|
| 74 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
| 75 | + { |
|
| 76 | + $this->_this_model_name = $this_model_name; |
|
| 77 | + $this->_other_model_name = $other_model_name; |
|
| 78 | + if (is_string($this->_blocking_delete)) { |
|
| 79 | + throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
| 80 | + "event_espresso"), |
|
| 81 | + get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Gets the model where this relation is defined. |
|
| 88 | + * |
|
| 89 | + * @return EEM_Base |
|
| 90 | + */ |
|
| 91 | + public function get_this_model() |
|
| 92 | + { |
|
| 93 | + return $this->_get_model($this->_this_model_name); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets the model which this relation establishes the relation TO (ie, |
|
| 99 | + * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
| 100 | + * |
|
| 101 | + * @return EEM_Base |
|
| 102 | + */ |
|
| 103 | + public function get_other_model() |
|
| 104 | + { |
|
| 105 | + return $this->_get_model($this->_other_model_name); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Internally used by get_this_model() and get_other_model() |
|
| 111 | + * |
|
| 112 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
| 113 | + * @return EEM_Base |
|
| 114 | + */ |
|
| 115 | + protected function _get_model($model_name) |
|
| 116 | + { |
|
| 117 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
| 118 | + $modelInstance->set_timezone($this->_timezone); |
|
| 119 | + return $modelInstance; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
| 125 | + * timezone set correctly. |
|
| 126 | + * |
|
| 127 | + * @param string $timezone timezone to set. |
|
| 128 | + */ |
|
| 129 | + public function set_timezone($timezone) |
|
| 130 | + { |
|
| 131 | + if ($timezone !== null) { |
|
| 132 | + $this->_timezone = $timezone; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param $other_table |
|
| 139 | + * @param $other_table_alias |
|
| 140 | + * @param $other_table_column |
|
| 141 | + * @param $this_table_alias |
|
| 142 | + * @param $this_table_join_column |
|
| 143 | + * @param string $extra_join_sql |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + protected function _left_join( |
|
| 147 | + $other_table, |
|
| 148 | + $other_table_alias, |
|
| 149 | + $other_table_column, |
|
| 150 | + $this_table_alias, |
|
| 151 | + $this_table_join_column, |
|
| 152 | + $extra_join_sql = '' |
|
| 153 | + ) { |
|
| 154 | + return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Gets all the model objects of type of other model related to $model_object, |
|
| 160 | + * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
| 161 | + * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
| 162 | + * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
| 163 | + * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
| 164 | + * |
|
| 165 | + * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
| 166 | + * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 167 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
| 168 | + * @return EE_Base_Class[] |
|
| 169 | + * @throws \EE_Error |
|
| 170 | + */ |
|
| 171 | + public function get_all_related( |
|
| 172 | + $model_object_or_id, |
|
| 173 | + $query_params = array(), |
|
| 174 | + $values_already_prepared_by_model_object = false |
|
| 175 | + ) { |
|
| 176 | + if ($values_already_prepared_by_model_object !== false) { |
|
| 177 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', |
|
| 178 | + __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
| 179 | + '4.8.1'); |
|
| 180 | + } |
|
| 181 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
| 182 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
| 183 | + . "." |
|
| 184 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
| 185 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
| 186 | + $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
| 187 | + return $this->get_other_model()->get_all($query_params); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
| 193 | + * |
|
| 194 | + * @param string $query_params |
|
| 195 | + * @return array |
|
| 196 | + */ |
|
| 197 | + protected function _disable_default_where_conditions_on_query_param($query_params) |
|
| 198 | + { |
|
| 199 | + if (! isset($query_params['default_where_conditions'])) { |
|
| 200 | + $query_params['default_where_conditions'] = 'none'; |
|
| 201 | + } |
|
| 202 | + return $query_params; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Deletes the related model objects which meet the query parameters. If no |
|
| 208 | + * parameters are specified, then all related model objects will be deleted. |
|
| 209 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
| 210 | + * model objects will only be soft-deleted. |
|
| 211 | + * |
|
| 212 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
| 213 | + * @param array $query_params |
|
| 214 | + * @return int of how many related models got deleted |
|
| 215 | + * @throws \EE_Error |
|
| 216 | + */ |
|
| 217 | + public function delete_all_related($model_object_or_id, $query_params = array()) |
|
| 218 | + { |
|
| 219 | + //for each thing we would delete, |
|
| 220 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
| 221 | + //determine if it's blocked by anything else before it can be deleted |
|
| 222 | + $deleted_count = 0; |
|
| 223 | + foreach ($related_model_objects as $related_model_object) { |
|
| 224 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
| 225 | + $model_object_or_id); |
|
| 226 | + /* @var $model_object_or_id EE_Base_Class */ |
|
| 227 | + if (! $delete_is_blocked) { |
|
| 228 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 229 | + $related_model_object->delete(); |
|
| 230 | + $deleted_count++; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + return $deleted_count; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Deletes the related model objects which meet the query parameters. If no |
|
| 239 | + * parameters are specified, then all related model objects will be deleted. |
|
| 240 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
| 241 | + * model objects will only be soft-deleted. |
|
| 242 | + * |
|
| 243 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
| 244 | + * @param array $query_params |
|
| 245 | + * @return int of how many related models got deleted |
|
| 246 | + * @throws \EE_Error |
|
| 247 | + */ |
|
| 248 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
| 249 | + { |
|
| 250 | + //for each thing we would delete, |
|
| 251 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
| 252 | + //determine if it's blocked by anything else before it can be deleted |
|
| 253 | + $deleted_count = 0; |
|
| 254 | + foreach ($related_model_objects as $related_model_object) { |
|
| 255 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
| 256 | + $model_object_or_id); |
|
| 257 | + /* @var $model_object_or_id EE_Base_Class */ |
|
| 258 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
| 259 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 260 | + $deleted_count++; |
|
| 261 | + if (! $delete_is_blocked) { |
|
| 262 | + $related_model_object->delete_permanently(); |
|
| 263 | + } else { |
|
| 264 | + //delete is blocked |
|
| 265 | + //brent and darren, in this case, wanted to just soft delete it then |
|
| 266 | + $related_model_object->delete(); |
|
| 267 | + } |
|
| 268 | + } else { |
|
| 269 | + //its not a soft-deletable thing anyways. do the normal logic. |
|
| 270 | + if (! $delete_is_blocked) { |
|
| 271 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
| 272 | + $related_model_object->delete(); |
|
| 273 | + $deleted_count++; |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + return $deleted_count; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * this just returns a model_object_id for incoming item that could be an object or id. |
|
| 283 | + * |
|
| 284 | + * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
| 285 | + * @throws EE_Error |
|
| 286 | + * @return int |
|
| 287 | + */ |
|
| 288 | + protected function _get_model_object_id($model_object_or_id) |
|
| 289 | + { |
|
| 290 | + $model_object_id = $model_object_or_id; |
|
| 291 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
| 292 | + $model_object_id = $model_object_or_id->ID(); |
|
| 293 | + } |
|
| 294 | + if (! $model_object_id) { |
|
| 295 | + throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
| 296 | + "event_espresso"), $this->get_other_model()->get_this_model_name(), |
|
| 297 | + $this->get_this_model()->get_this_model_name())); |
|
| 298 | + } |
|
| 299 | + return $model_object_id; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Gets the SQL string for performing the join between this model and the other model. |
|
| 305 | + * |
|
| 306 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
| 307 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
| 308 | + * other_model_primary_table.fk" etc |
|
| 309 | + */ |
|
| 310 | + abstract public function get_join_statement($model_relation_chain); |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
| 315 | + * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
| 316 | + * relationship only allows this model to be related to a single other model of this type) |
|
| 317 | + * |
|
| 318 | + * @param $this_obj_or_id |
|
| 319 | + * @param $other_obj_or_id |
|
| 320 | + * @param array $extra_join_model_fields_n_values |
|
| 321 | + * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
| 322 | + * $other_obj_or_id) |
|
| 323 | + */ |
|
| 324 | + abstract public function add_relation_to( |
|
| 325 | + $this_obj_or_id, |
|
| 326 | + $other_obj_or_id, |
|
| 327 | + $extra_join_model_fields_n_values = array() |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
| 333 | + * model objects |
|
| 334 | + * |
|
| 335 | + * @param $this_obj_or_id |
|
| 336 | + * @param $other_obj_or_id |
|
| 337 | + * @param array $where_query |
|
| 338 | + * @return bool |
|
| 339 | + */ |
|
| 340 | + abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Removes ALL relation instances for this relation obj |
|
| 345 | + * |
|
| 346 | + * @param EE_Base_Class|int $this_obj_or_id |
|
| 347 | + * @param array $where_query_param like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 348 | + * @return EE_Base_Class[] |
|
| 349 | + * @throws \EE_Error |
|
| 350 | + */ |
|
| 351 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
| 352 | + { |
|
| 353 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
| 354 | + $objs_removed = array(); |
|
| 355 | + foreach ($related_things as $related_thing) { |
|
| 356 | + $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
| 357 | + } |
|
| 358 | + return $objs_removed; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * If you aren't allowed to delete this model when there are related models across this |
|
| 364 | + * relation object, return true. Otherwise, if you can delete this model even though |
|
| 365 | + * related objects exist, returns false. |
|
| 366 | + * |
|
| 367 | + * @return boolean |
|
| 368 | + */ |
|
| 369 | + public function block_delete_if_related_models_exist() |
|
| 370 | + { |
|
| 371 | + return $this->_blocking_delete; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Gets the error message to show |
|
| 377 | + * |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + public function get_deletion_error_message() |
|
| 381 | + { |
|
| 382 | + if ($this->_blocking_delete_error_message) { |
|
| 383 | + return $this->_blocking_delete_error_message; |
|
| 384 | + } else { |
|
| 385 | 385 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
| 386 | - return sprintf( |
|
| 387 | - __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
| 388 | - "event_espresso"), |
|
| 389 | - $this->get_this_model()->item_name(1), |
|
| 390 | - $this->get_other_model()->item_name(1), |
|
| 391 | - $this->get_other_model()->item_name(2) |
|
| 392 | - ); |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Returns whatever is set as the nicename for the object. |
|
| 398 | - * |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function getSchemaDescription() |
|
| 402 | - { |
|
| 403 | - $description = $this instanceof EE_Belongs_To_Relation |
|
| 404 | - ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
| 405 | - : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
| 406 | - return sprintf( |
|
| 407 | - $description, |
|
| 408 | - $this->get_other_model()->get_this_model_name(), |
|
| 409 | - $this->get_this_model()->get_this_model_name() |
|
| 410 | - ); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Returns whatever is set as the $_schema_type property for the object. |
|
| 415 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 416 | - * |
|
| 417 | - * @return string|array |
|
| 418 | - */ |
|
| 419 | - public function getSchemaType() |
|
| 420 | - { |
|
| 421 | - return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 426 | - * this method and return the properties for the schema. |
|
| 427 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 428 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 429 | - * |
|
| 430 | - * @return array |
|
| 431 | - */ |
|
| 432 | - public function getSchemaProperties() |
|
| 433 | - { |
|
| 434 | - return array(); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * If a child class has enum values, they should override this method and provide a simple array |
|
| 439 | - * of the enum values. |
|
| 440 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 441 | - * are set on the instantiated object that could be filtered after construct. |
|
| 442 | - * |
|
| 443 | - * @return array |
|
| 444 | - */ |
|
| 445 | - public function getSchemaEnum() |
|
| 446 | - { |
|
| 447 | - return array(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * This returns the value of the $_schema_format property on the object. |
|
| 452 | - * |
|
| 453 | - * @return string |
|
| 454 | - */ |
|
| 455 | - public function getSchemaFormat() |
|
| 456 | - { |
|
| 457 | - return array(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * This returns the value of the $_schema_readonly property on the object. |
|
| 462 | - * |
|
| 463 | - * @return bool |
|
| 464 | - */ |
|
| 465 | - public function getSchemaReadonly() |
|
| 466 | - { |
|
| 467 | - return true; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * This returns elements used to represent this field in the json schema. |
|
| 472 | - * |
|
| 473 | - * @link http://json-schema.org/ |
|
| 474 | - * @return array |
|
| 475 | - */ |
|
| 476 | - public function getSchema() |
|
| 477 | - { |
|
| 478 | - $schema = array( |
|
| 479 | - 'description' => $this->getSchemaDescription(), |
|
| 480 | - 'type' => $this->getSchemaType(), |
|
| 481 | - 'relation' => true, |
|
| 482 | - 'relation_type' => get_class($this), |
|
| 483 | - 'readonly' => $this->getSchemaReadonly() |
|
| 484 | - ); |
|
| 485 | - |
|
| 486 | - if ($this instanceof EE_HABTM_Relation) { |
|
| 487 | - $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - if ($this->getSchemaType() === 'array') { |
|
| 491 | - $schema['items'] = array( |
|
| 492 | - 'type' => 'object' |
|
| 493 | - ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $schema; |
|
| 497 | - } |
|
| 386 | + return sprintf( |
|
| 387 | + __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
| 388 | + "event_espresso"), |
|
| 389 | + $this->get_this_model()->item_name(1), |
|
| 390 | + $this->get_other_model()->item_name(1), |
|
| 391 | + $this->get_other_model()->item_name(2) |
|
| 392 | + ); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Returns whatever is set as the nicename for the object. |
|
| 398 | + * |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function getSchemaDescription() |
|
| 402 | + { |
|
| 403 | + $description = $this instanceof EE_Belongs_To_Relation |
|
| 404 | + ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
| 405 | + : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
| 406 | + return sprintf( |
|
| 407 | + $description, |
|
| 408 | + $this->get_other_model()->get_this_model_name(), |
|
| 409 | + $this->get_this_model()->get_this_model_name() |
|
| 410 | + ); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Returns whatever is set as the $_schema_type property for the object. |
|
| 415 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 416 | + * |
|
| 417 | + * @return string|array |
|
| 418 | + */ |
|
| 419 | + public function getSchemaType() |
|
| 420 | + { |
|
| 421 | + return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 426 | + * this method and return the properties for the schema. |
|
| 427 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 428 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 429 | + * |
|
| 430 | + * @return array |
|
| 431 | + */ |
|
| 432 | + public function getSchemaProperties() |
|
| 433 | + { |
|
| 434 | + return array(); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * If a child class has enum values, they should override this method and provide a simple array |
|
| 439 | + * of the enum values. |
|
| 440 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 441 | + * are set on the instantiated object that could be filtered after construct. |
|
| 442 | + * |
|
| 443 | + * @return array |
|
| 444 | + */ |
|
| 445 | + public function getSchemaEnum() |
|
| 446 | + { |
|
| 447 | + return array(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * This returns the value of the $_schema_format property on the object. |
|
| 452 | + * |
|
| 453 | + * @return string |
|
| 454 | + */ |
|
| 455 | + public function getSchemaFormat() |
|
| 456 | + { |
|
| 457 | + return array(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * This returns the value of the $_schema_readonly property on the object. |
|
| 462 | + * |
|
| 463 | + * @return bool |
|
| 464 | + */ |
|
| 465 | + public function getSchemaReadonly() |
|
| 466 | + { |
|
| 467 | + return true; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * This returns elements used to represent this field in the json schema. |
|
| 472 | + * |
|
| 473 | + * @link http://json-schema.org/ |
|
| 474 | + * @return array |
|
| 475 | + */ |
|
| 476 | + public function getSchema() |
|
| 477 | + { |
|
| 478 | + $schema = array( |
|
| 479 | + 'description' => $this->getSchemaDescription(), |
|
| 480 | + 'type' => $this->getSchemaType(), |
|
| 481 | + 'relation' => true, |
|
| 482 | + 'relation_type' => get_class($this), |
|
| 483 | + 'readonly' => $this->getSchemaReadonly() |
|
| 484 | + ); |
|
| 485 | + |
|
| 486 | + if ($this instanceof EE_HABTM_Relation) { |
|
| 487 | + $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + if ($this->getSchemaType() === 'array') { |
|
| 491 | + $schema['items'] = array( |
|
| 492 | + 'type' => 'object' |
|
| 493 | + ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $schema; |
|
| 497 | + } |
|
| 498 | 498 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use EE_Datetime_Field; |
| 10 | 10 | |
| 11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 12 | - exit('No direct script access allowed'); |
|
| 12 | + exit('No direct script access allowed'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | |
@@ -27,1182 +27,1182 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var Calculated_Model_Fields |
|
| 32 | - */ |
|
| 33 | - protected $_fields_calculator; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Read constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - parent::__construct(); |
|
| 43 | - $this->_fields_calculator = new Calculated_Model_Fields(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
| 50 | - * |
|
| 51 | - * @param \WP_REST_Request $request |
|
| 52 | - * @return \WP_REST_Response|\WP_Error |
|
| 53 | - */ |
|
| 54 | - public static function handle_request_get_all(\WP_REST_Request $request) |
|
| 55 | - { |
|
| 56 | - $controller = new Read(); |
|
| 57 | - try { |
|
| 58 | - $matches = $controller->parse_route( |
|
| 59 | - $request->get_route(), |
|
| 60 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 61 | - array('version', 'model') |
|
| 62 | - ); |
|
| 63 | - $controller->set_requested_version($matches['version']); |
|
| 64 | - $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 65 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 66 | - return $controller->send_response( |
|
| 67 | - new \WP_Error( |
|
| 68 | - 'endpoint_parsing_error', |
|
| 69 | - sprintf( |
|
| 70 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 71 | - 'event_espresso'), |
|
| 72 | - $model_name_singular |
|
| 73 | - ) |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - return $controller->send_response( |
|
| 78 | - $controller->get_entities_from_model( |
|
| 79 | - $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 80 | - $request |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - } catch (\Exception $e) { |
|
| 84 | - return $controller->send_response($e); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Prepares and returns schema for any OPTIONS request. |
|
| 91 | - * |
|
| 92 | - * @param string $model_name Something like `Event` or `Registration` |
|
| 93 | - * @param string $version The API endpoint version being used. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public static function handle_schema_request($model_name, $version) |
|
| 97 | - { |
|
| 98 | - $controller = new Read(); |
|
| 99 | - try { |
|
| 100 | - $controller->set_requested_version($version); |
|
| 101 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
| 102 | - return array(); |
|
| 103 | - } |
|
| 104 | - //get the model for this version |
|
| 105 | - $model = $controller->get_model_version_info()->load_model($model_name); |
|
| 106 | - $model_schema = new JsonModelSchema($model); |
|
| 107 | - return $model_schema->getModelSchemaForRelations( |
|
| 108 | - $controller->get_model_version_info()->relation_settings($model), |
|
| 109 | - $controller->_add_extra_fields_to_schema( |
|
| 110 | - $model, |
|
| 111 | - $model_schema->getModelSchemaForFields( |
|
| 112 | - $controller->get_model_version_info()->fields_on_model_in_this_version($model), |
|
| 113 | - $model_schema->getInitialSchemaStructure() |
|
| 114 | - ) |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 117 | - } catch (\Exception $e) { |
|
| 118 | - return array(); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Adds additional fields to the schema |
|
| 125 | - * The REST API returns a GMT value field for each datetime field in the resource. Thus the description about this |
|
| 126 | - * needs to be added to the schema. |
|
| 127 | - * |
|
| 128 | - * @param \EEM_Base $model |
|
| 129 | - * @param string $schema |
|
| 130 | - */ |
|
| 131 | - protected function _add_extra_fields_to_schema(\EEM_Base $model, $schema) |
|
| 132 | - { |
|
| 133 | - foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field) { |
|
| 134 | - if ($field instanceof EE_Datetime_Field) { |
|
| 135 | - $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
| 136 | - //modify the description |
|
| 137 | - $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
| 138 | - esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
|
| 139 | - $field->get_nicename() |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return $schema; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Used to figure out the route from the request when a `WP_REST_Request` object is not available |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - protected function get_route_from_request() { |
|
| 154 | - if (isset($GLOBALS['wp']) |
|
| 155 | - && $GLOBALS['wp'] instanceof \WP |
|
| 156 | - && isset($GLOBALS['wp']->query_vars['rest_route'] ) |
|
| 157 | - ) { |
|
| 158 | - return $GLOBALS['wp']->query_vars['rest_route']; |
|
| 159 | - } else { |
|
| 160 | - return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Gets a single entity related to the model indicated in the path and its id |
|
| 168 | - * |
|
| 169 | - * @param \WP_REST_Request $request |
|
| 170 | - * @return \WP_REST_Response|\WP_Error |
|
| 171 | - */ |
|
| 172 | - public static function handle_request_get_one(\WP_REST_Request $request) |
|
| 173 | - { |
|
| 174 | - $controller = new Read(); |
|
| 175 | - try { |
|
| 176 | - $matches = $controller->parse_route( |
|
| 177 | - $request->get_route(), |
|
| 178 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 179 | - array('version', 'model', 'id')); |
|
| 180 | - $controller->set_requested_version($matches['version']); |
|
| 181 | - $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 182 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 183 | - return $controller->send_response( |
|
| 184 | - new \WP_Error( |
|
| 185 | - 'endpoint_parsing_error', |
|
| 186 | - sprintf( |
|
| 187 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 188 | - 'event_espresso'), |
|
| 189 | - $model_name_singular |
|
| 190 | - ) |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - return $controller->send_response( |
|
| 195 | - $controller->get_entity_from_model( |
|
| 196 | - $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 197 | - $request |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - } catch (\Exception $e) { |
|
| 201 | - return $controller->send_response($e); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Gets all the related entities (or if its a belongs-to relation just the one) |
|
| 209 | - * to the item with the given id |
|
| 210 | - * |
|
| 211 | - * @param \WP_REST_Request $request |
|
| 212 | - * @return \WP_REST_Response|\WP_Error |
|
| 213 | - */ |
|
| 214 | - public static function handle_request_get_related(\WP_REST_Request $request) |
|
| 215 | - { |
|
| 216 | - $controller = new Read(); |
|
| 217 | - try { |
|
| 218 | - $matches = $controller->parse_route( |
|
| 219 | - $request->get_route(), |
|
| 220 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 221 | - array('version', 'model', 'id', 'related_model') |
|
| 222 | - ); |
|
| 223 | - $controller->set_requested_version($matches['version']); |
|
| 224 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 225 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 226 | - return $controller->send_response( |
|
| 227 | - new \WP_Error( |
|
| 228 | - 'endpoint_parsing_error', |
|
| 229 | - sprintf( |
|
| 230 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 231 | - 'event_espresso'), |
|
| 232 | - $main_model_name_singular |
|
| 233 | - ) |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
| 238 | - //assume the related model name is plural and try to find the model's name |
|
| 239 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
| 240 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 241 | - //so the word didn't singularize well. Maybe that's just because it's a singular word? |
|
| 242 | - $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
| 243 | - } |
|
| 244 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 245 | - return $controller->send_response( |
|
| 246 | - new \WP_Error( |
|
| 247 | - 'endpoint_parsing_error', |
|
| 248 | - sprintf( |
|
| 249 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 250 | - 'event_espresso'), |
|
| 251 | - $related_model_name_singular |
|
| 252 | - ) |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - return $controller->send_response( |
|
| 257 | - $controller->get_entities_from_relation( |
|
| 258 | - $request->get_param('id'), |
|
| 259 | - $main_model->related_settings_for($related_model_name_singular), |
|
| 260 | - $request |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } catch (\Exception $e) { |
|
| 264 | - return $controller->send_response($e); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Gets a collection for the given model and filters |
|
| 272 | - * |
|
| 273 | - * @param \EEM_Base $model |
|
| 274 | - * @param \WP_REST_Request $request |
|
| 275 | - * @return array|\WP_Error |
|
| 276 | - */ |
|
| 277 | - public function get_entities_from_model($model, $request) |
|
| 278 | - { |
|
| 279 | - $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
| 280 | - if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 281 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 282 | - return new \WP_Error( |
|
| 283 | - sprintf('rest_%s_cannot_list', $model_name_plural), |
|
| 284 | - sprintf( |
|
| 285 | - __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
| 286 | - $model_name_plural, |
|
| 287 | - Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
| 288 | - ), |
|
| 289 | - array('status' => 403) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - if (! $request->get_header('no_rest_headers')) { |
|
| 293 | - $this->_set_headers_from_query_params($model, $query_params); |
|
| 294 | - } |
|
| 295 | - /** @type array $results */ |
|
| 296 | - $results = $model->get_all_wpdb_results($query_params); |
|
| 297 | - $nice_results = array(); |
|
| 298 | - foreach ($results as $result) { |
|
| 299 | - $nice_results[] = $this->create_entity_from_wpdb_result( |
|
| 300 | - $model, |
|
| 301 | - $result, |
|
| 302 | - $request |
|
| 303 | - ); |
|
| 304 | - } |
|
| 305 | - return $nice_results; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param array $primary_model_query_params query params for finding the item from which |
|
| 312 | - * relations will be based |
|
| 313 | - * @param \EE_Model_Relation_Base $relation |
|
| 314 | - * @param \WP_REST_Request $request |
|
| 315 | - * @return \WP_Error|array |
|
| 316 | - */ |
|
| 317 | - protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) |
|
| 318 | - { |
|
| 319 | - $context = $this->validate_context($request->get_param('caps')); |
|
| 320 | - $model = $relation->get_this_model(); |
|
| 321 | - $related_model = $relation->get_other_model(); |
|
| 322 | - if (! isset($primary_model_query_params[0])) { |
|
| 323 | - $primary_model_query_params[0] = array(); |
|
| 324 | - } |
|
| 325 | - //check if they can access the 1st model object |
|
| 326 | - $primary_model_query_params = array( |
|
| 327 | - 0 => $primary_model_query_params[0], |
|
| 328 | - 'limit' => 1, |
|
| 329 | - ); |
|
| 330 | - if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 331 | - $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
| 332 | - } |
|
| 333 | - $restricted_query_params = $primary_model_query_params; |
|
| 334 | - $restricted_query_params['caps'] = $context; |
|
| 335 | - $this->_set_debug_info('main model query params', $restricted_query_params); |
|
| 336 | - $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
| 337 | - if ( |
|
| 338 | - ! ( |
|
| 339 | - Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
| 340 | - && $model->exists($restricted_query_params) |
|
| 341 | - ) |
|
| 342 | - ) { |
|
| 343 | - if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 344 | - $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
| 345 | - } else { |
|
| 346 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
| 347 | - } |
|
| 348 | - return new \WP_Error( |
|
| 349 | - sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
| 350 | - sprintf( |
|
| 351 | - __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', |
|
| 352 | - 'event_espresso'), |
|
| 353 | - $related_model_name_maybe_plural, |
|
| 354 | - $relation->get_this_model()->get_this_model_name(), |
|
| 355 | - implode( |
|
| 356 | - ',', |
|
| 357 | - array_keys( |
|
| 358 | - Capabilities::get_missing_permissions($related_model, $context) |
|
| 359 | - ) |
|
| 360 | - ) |
|
| 361 | - ), |
|
| 362 | - array('status' => 403) |
|
| 363 | - ); |
|
| 364 | - } |
|
| 365 | - $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
| 366 | - foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
| 367 | - $query_params[0][$relation->get_this_model()->get_this_model_name() |
|
| 368 | - . '.' |
|
| 369 | - . $where_condition_key] = $where_condition_value; |
|
| 370 | - } |
|
| 371 | - $query_params['default_where_conditions'] = 'none'; |
|
| 372 | - $query_params['caps'] = $context; |
|
| 373 | - if (! $request->get_header('no_rest_headers')) { |
|
| 374 | - $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
| 375 | - } |
|
| 376 | - /** @type array $results */ |
|
| 377 | - $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
| 378 | - $nice_results = array(); |
|
| 379 | - foreach ($results as $result) { |
|
| 380 | - $nice_result = $this->create_entity_from_wpdb_result( |
|
| 381 | - $relation->get_other_model(), |
|
| 382 | - $result, |
|
| 383 | - $request |
|
| 384 | - ); |
|
| 385 | - if ($relation instanceof \EE_HABTM_Relation) { |
|
| 386 | - //put the unusual stuff (properties from the HABTM relation) first, and make sure |
|
| 387 | - //if there are conflicts we prefer the properties from the main model |
|
| 388 | - $join_model_result = $this->create_entity_from_wpdb_result( |
|
| 389 | - $relation->get_join_model(), |
|
| 390 | - $result, |
|
| 391 | - $request |
|
| 392 | - ); |
|
| 393 | - $joined_result = array_merge($nice_result, $join_model_result); |
|
| 394 | - //but keep the meta stuff from the main model |
|
| 395 | - if (isset($nice_result['meta'])) { |
|
| 396 | - $joined_result['meta'] = $nice_result['meta']; |
|
| 397 | - } |
|
| 398 | - $nice_result = $joined_result; |
|
| 399 | - } |
|
| 400 | - $nice_results[] = $nice_result; |
|
| 401 | - } |
|
| 402 | - if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 403 | - return array_shift($nice_results); |
|
| 404 | - } else { |
|
| 405 | - return $nice_results; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets the collection for given relation object |
|
| 413 | - * The same as Read::get_entities_from_model(), except if the relation |
|
| 414 | - * is a HABTM relation, in which case it merges any non-foreign-key fields from |
|
| 415 | - * the join-model-object into the results |
|
| 416 | - * |
|
| 417 | - * @param string $id the ID of the thing we are fetching related stuff from |
|
| 418 | - * @param \EE_Model_Relation_Base $relation |
|
| 419 | - * @param \WP_REST_Request $request |
|
| 420 | - * @return array|\WP_Error |
|
| 421 | - * @throws \EE_Error |
|
| 422 | - */ |
|
| 423 | - public function get_entities_from_relation($id, $relation, $request) |
|
| 424 | - { |
|
| 425 | - if (! $relation->get_this_model()->has_primary_key_field()) { |
|
| 426 | - throw new \EE_Error( |
|
| 427 | - sprintf( |
|
| 428 | - __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
|
| 429 | - 'event_espresso'), |
|
| 430 | - $relation->get_this_model()->get_this_model_name() |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $this->_get_entities_from_relation( |
|
| 435 | - array( |
|
| 436 | - array( |
|
| 437 | - $relation->get_this_model()->primary_key_name() => $id, |
|
| 438 | - ), |
|
| 439 | - ), |
|
| 440 | - $relation, |
|
| 441 | - $request |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Sets the headers that are based on the model and query params, |
|
| 449 | - * like the total records. This should only be called on the original request |
|
| 450 | - * from the client, not on subsequent internal |
|
| 451 | - * |
|
| 452 | - * @param \EEM_Base $model |
|
| 453 | - * @param array $query_params |
|
| 454 | - * @return void |
|
| 455 | - */ |
|
| 456 | - protected function _set_headers_from_query_params($model, $query_params) |
|
| 457 | - { |
|
| 458 | - $this->_set_debug_info('model query params', $query_params); |
|
| 459 | - $this->_set_debug_info('missing caps', |
|
| 460 | - Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
| 461 | - //normally the limit to a 2-part array, where the 2nd item is the limit |
|
| 462 | - if (! isset($query_params['limit'])) { |
|
| 463 | - $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 464 | - } |
|
| 465 | - if (is_array($query_params['limit'])) { |
|
| 466 | - $limit_parts = $query_params['limit']; |
|
| 467 | - } else { |
|
| 468 | - $limit_parts = explode(',', $query_params['limit']); |
|
| 469 | - if (count($limit_parts) == 1) { |
|
| 470 | - $limit_parts = array(0, $limit_parts[0]); |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - //remove the group by and having parts of the query, as those will |
|
| 474 | - //make the sql query return an array of values, instead of just a single value |
|
| 475 | - unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
| 476 | - $count = $model->count($query_params, null, true); |
|
| 477 | - $pages = $count / $limit_parts[1]; |
|
| 478 | - $this->_set_response_header('Total', $count, false); |
|
| 479 | - $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
| 480 | - $this->_set_response_header('TotalPages', ceil($pages), false); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Changes database results into REST API entities |
|
| 487 | - * |
|
| 488 | - * @param \EEM_Base $model |
|
| 489 | - * @param array $db_row like results from $wpdb->get_results() |
|
| 490 | - * @param \WP_REST_Request $rest_request |
|
| 491 | - * @param string $deprecated no longer used |
|
| 492 | - * @return array ready for being converted into json for sending to client |
|
| 493 | - */ |
|
| 494 | - public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
|
| 495 | - { |
|
| 496 | - if (! $rest_request instanceof \WP_REST_Request) { |
|
| 497 | - //ok so this was called in the old style, where the 3rd arg was |
|
| 498 | - //$include, and the 4th arg was $context |
|
| 499 | - //now setup the request just to avoid fatal errors, although we won't be able |
|
| 500 | - //to truly make use of it because it's kinda devoid of info |
|
| 501 | - $rest_request = new \WP_REST_Request(); |
|
| 502 | - $rest_request->set_param('include', $rest_request); |
|
| 503 | - $rest_request->set_param('caps', $deprecated); |
|
| 504 | - } |
|
| 505 | - if ($rest_request->get_param('caps') == null) { |
|
| 506 | - $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
| 507 | - } |
|
| 508 | - $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
| 509 | - $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
| 510 | - $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
| 511 | - $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
| 512 | - $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
| 513 | - $entity_array = apply_filters( |
|
| 514 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
| 515 | - $entity_array, |
|
| 516 | - $model, |
|
| 517 | - $rest_request->get_param('caps'), |
|
| 518 | - $rest_request, |
|
| 519 | - $this |
|
| 520 | - ); |
|
| 521 | - $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
|
| 522 | - $entity_array, |
|
| 523 | - $model, |
|
| 524 | - $rest_request->get_param('caps'), |
|
| 525 | - $this->get_model_version_info(), |
|
| 526 | - $model->get_index_primary_key_string( |
|
| 527 | - $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 528 | - ) |
|
| 529 | - ); |
|
| 530 | - $this->_set_debug_info( |
|
| 531 | - 'inaccessible fields', |
|
| 532 | - array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
| 533 | - ); |
|
| 534 | - return apply_filters( |
|
| 535 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
|
| 536 | - $result_without_inaccessible_fields, |
|
| 537 | - $model, |
|
| 538 | - $rest_request->get_param('caps') |
|
| 539 | - ); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Creates a REST entity array (JSON object we're going to return in the response, but |
|
| 546 | - * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry), |
|
| 547 | - * from $wpdb->get_row( $sql, ARRAY_A) |
|
| 548 | - * |
|
| 549 | - * @param \EEM_Base $model |
|
| 550 | - * @param array $db_row |
|
| 551 | - * @return array entity mostly ready for converting to JSON and sending in the response |
|
| 552 | - */ |
|
| 553 | - protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) |
|
| 554 | - { |
|
| 555 | - $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
| 556 | - $result = array_intersect_key($result, |
|
| 557 | - $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
| 558 | - foreach ($result as $field_name => $raw_field_value) { |
|
| 559 | - $field_obj = $model->field_settings_for($field_name); |
|
| 560 | - $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
| 561 | - if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
| 562 | - unset($result[$field_name]); |
|
| 563 | - } elseif ( |
|
| 564 | - $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
| 565 | - ) { |
|
| 566 | - $result[$field_name] = array( |
|
| 567 | - 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 568 | - 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
| 569 | - ); |
|
| 570 | - } elseif ( |
|
| 571 | - $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
| 572 | - ) { |
|
| 573 | - $result[$field_name] = array( |
|
| 574 | - 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 575 | - 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
| 576 | - ); |
|
| 577 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 578 | - if ($field_value instanceof \DateTime) { |
|
| 579 | - $timezone = $field_value->getTimezone(); |
|
| 580 | - $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
| 581 | - $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 582 | - $field_obj, |
|
| 583 | - $field_value, |
|
| 584 | - $this->get_model_version_info()->requested_version() |
|
| 585 | - ); |
|
| 586 | - $field_value->setTimezone($timezone); |
|
| 587 | - $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 588 | - $field_obj, |
|
| 589 | - $field_value, |
|
| 590 | - $this->get_model_version_info()->requested_version() |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - } else { |
|
| 594 | - $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 595 | - $field_obj, |
|
| 596 | - $field_obj->prepare_for_get($field_value), |
|
| 597 | - $this->get_model_version_info()->requested_version() |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - return $result; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Adds a few extra fields to the entity response |
|
| 608 | - * |
|
| 609 | - * @param \EEM_Base $model |
|
| 610 | - * @param array $db_row |
|
| 611 | - * @param array $entity_array |
|
| 612 | - * @return array modified entity |
|
| 613 | - */ |
|
| 614 | - protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) |
|
| 615 | - { |
|
| 616 | - if ($model instanceof \EEM_CPT_Base) { |
|
| 617 | - $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
| 618 | - } |
|
| 619 | - return $entity_array; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Gets links we want to add to the response |
|
| 626 | - * |
|
| 627 | - * @global \WP_REST_Server $wp_rest_server |
|
| 628 | - * @param \EEM_Base $model |
|
| 629 | - * @param array $db_row |
|
| 630 | - * @param array $entity_array |
|
| 631 | - * @return array the _links item in the entity |
|
| 632 | - */ |
|
| 633 | - protected function _get_entity_links($model, $db_row, $entity_array) |
|
| 634 | - { |
|
| 635 | - //add basic links |
|
| 636 | - $links = array(); |
|
| 637 | - if ($model->has_primary_key_field()) { |
|
| 638 | - $links['self'] = array( |
|
| 639 | - array( |
|
| 640 | - 'href' => $this->get_versioned_link_to( |
|
| 641 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 642 | - . '/' |
|
| 643 | - . $entity_array[$model->primary_key_name()] |
|
| 644 | - ), |
|
| 645 | - ), |
|
| 646 | - ); |
|
| 647 | - } |
|
| 648 | - $links['collection'] = array( |
|
| 649 | - array( |
|
| 650 | - 'href' => $this->get_versioned_link_to( |
|
| 651 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 652 | - ), |
|
| 653 | - ), |
|
| 654 | - ); |
|
| 655 | - //add links to related models |
|
| 656 | - if ($model->has_primary_key_field()) { |
|
| 657 | - foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 658 | - $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
| 659 | - $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
| 660 | - array( |
|
| 661 | - 'href' => $this->get_versioned_link_to( |
|
| 662 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 663 | - . '/' |
|
| 664 | - . $entity_array[$model->primary_key_name()] |
|
| 665 | - . '/' |
|
| 666 | - . $related_model_part |
|
| 667 | - ), |
|
| 668 | - 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
| 669 | - ), |
|
| 670 | - ); |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - return $links; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Adds the included models indicated in the request to the entity provided |
|
| 680 | - * |
|
| 681 | - * @param \EEM_Base $model |
|
| 682 | - * @param \WP_REST_Request $rest_request |
|
| 683 | - * @param array $entity_array |
|
| 684 | - * @param array $db_row |
|
| 685 | - * @return array the modified entity |
|
| 686 | - */ |
|
| 687 | - protected function _include_requested_models( |
|
| 688 | - \EEM_Base $model, |
|
| 689 | - \WP_REST_Request $rest_request, |
|
| 690 | - $entity_array, |
|
| 691 | - $db_row = array() |
|
| 692 | - ) { |
|
| 693 | - //if $db_row not included, hope the entity array has what we need |
|
| 694 | - if (! $db_row) { |
|
| 695 | - $db_row = $entity_array; |
|
| 696 | - } |
|
| 697 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
| 698 | - $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
| 699 | - //if they passed in * or didn't specify any includes, return everything |
|
| 700 | - if (! in_array('*', $includes_for_this_model) |
|
| 701 | - && ! empty($includes_for_this_model) |
|
| 702 | - ) { |
|
| 703 | - if ($model->has_primary_key_field()) { |
|
| 704 | - //always include the primary key. ya just gotta know that at least |
|
| 705 | - $includes_for_this_model[] = $model->primary_key_name(); |
|
| 706 | - } |
|
| 707 | - if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
| 708 | - $includes_for_this_model[] = '_calculated_fields'; |
|
| 709 | - } |
|
| 710 | - $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
| 711 | - } |
|
| 712 | - $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
| 713 | - foreach ($relation_settings as $relation_name => $relation_obj) { |
|
| 714 | - $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
|
| 715 | - $rest_request->get_param('include'), |
|
| 716 | - $relation_name |
|
| 717 | - ); |
|
| 718 | - $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
|
| 719 | - $rest_request->get_param('calculate'), |
|
| 720 | - $relation_name |
|
| 721 | - ); |
|
| 722 | - //did they specify they wanted to include a related model, or |
|
| 723 | - //specific fields from a related model? |
|
| 724 | - //or did they specify to calculate a field from a related model? |
|
| 725 | - if ($related_fields_to_include || $related_fields_to_calculate) { |
|
| 726 | - //if so, we should include at least some part of the related model |
|
| 727 | - $pretend_related_request = new \WP_REST_Request(); |
|
| 728 | - $pretend_related_request->set_query_params( |
|
| 729 | - array( |
|
| 730 | - 'caps' => $rest_request->get_param('caps'), |
|
| 731 | - 'include' => $related_fields_to_include, |
|
| 732 | - 'calculate' => $related_fields_to_calculate, |
|
| 733 | - ) |
|
| 734 | - ); |
|
| 735 | - $pretend_related_request->add_header('no_rest_headers', true); |
|
| 736 | - $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
|
| 737 | - $model->get_index_primary_key_string( |
|
| 738 | - $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 739 | - ) |
|
| 740 | - ); |
|
| 741 | - $related_results = $this->_get_entities_from_relation( |
|
| 742 | - $primary_model_query_params, |
|
| 743 | - $relation_obj, |
|
| 744 | - $pretend_related_request |
|
| 745 | - ); |
|
| 746 | - $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results |
|
| 747 | - instanceof |
|
| 748 | - \WP_Error |
|
| 749 | - ? null |
|
| 750 | - : $related_results; |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - return $entity_array; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Returns a new array with all the names of models removed. Eg |
|
| 760 | - * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' ) |
|
| 761 | - * |
|
| 762 | - * @param array $arr |
|
| 763 | - * @return array |
|
| 764 | - */ |
|
| 765 | - private function _remove_model_names_from_array($arr) |
|
| 766 | - { |
|
| 767 | - return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Gets the calculated fields for the response |
|
| 774 | - * |
|
| 775 | - * @param \EEM_Base $model |
|
| 776 | - * @param array $wpdb_row |
|
| 777 | - * @param \WP_REST_Request $rest_request |
|
| 778 | - * @return \stdClass the _calculations item in the entity |
|
| 779 | - */ |
|
| 780 | - protected function _get_entity_calculations($model, $wpdb_row, $rest_request) |
|
| 781 | - { |
|
| 782 | - $calculated_fields = $this->explode_and_get_items_prefixed_with( |
|
| 783 | - $rest_request->get_param('calculate'), |
|
| 784 | - '' |
|
| 785 | - ); |
|
| 786 | - //note: setting calculate=* doesn't do anything |
|
| 787 | - $calculated_fields_to_return = new \stdClass(); |
|
| 788 | - foreach ($calculated_fields as $field_to_calculate) { |
|
| 789 | - try { |
|
| 790 | - $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
|
| 791 | - null, |
|
| 792 | - $this->_fields_calculator->retrieve_calculated_field_value( |
|
| 793 | - $model, |
|
| 794 | - $field_to_calculate, |
|
| 795 | - $wpdb_row, |
|
| 796 | - $rest_request, |
|
| 797 | - $this |
|
| 798 | - ), |
|
| 799 | - $this->get_model_version_info()->requested_version() |
|
| 800 | - ); |
|
| 801 | - } catch (Rest_Exception $e) { |
|
| 802 | - //if we don't have permission to read it, just leave it out. but let devs know about the problem |
|
| 803 | - $this->_set_response_header( |
|
| 804 | - 'Notices-Field-Calculation-Errors[' |
|
| 805 | - . $e->get_string_code() |
|
| 806 | - . '][' |
|
| 807 | - . $model->get_this_model_name() |
|
| 808 | - . '][' |
|
| 809 | - . $field_to_calculate |
|
| 810 | - . ']', |
|
| 811 | - $e->getMessage(), |
|
| 812 | - true |
|
| 813 | - ); |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - return $calculated_fields_to_return; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Gets the full URL to the resource, taking the requested version into account |
|
| 823 | - * |
|
| 824 | - * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
|
| 825 | - * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
|
| 826 | - */ |
|
| 827 | - public function get_versioned_link_to($link_part_after_version_and_slash) |
|
| 828 | - { |
|
| 829 | - return rest_url( |
|
| 830 | - \EED_Core_Rest_Api::ee_api_namespace |
|
| 831 | - . $this->get_model_version_info()->requested_version() |
|
| 832 | - . '/' |
|
| 833 | - . $link_part_after_version_and_slash |
|
| 834 | - ); |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * Gets the correct lowercase name for the relation in the API according |
|
| 841 | - * to the relation's type |
|
| 842 | - * |
|
| 843 | - * @param string $relation_name |
|
| 844 | - * @param \EE_Model_Relation_Base $relation_obj |
|
| 845 | - * @return string |
|
| 846 | - */ |
|
| 847 | - public static function get_related_entity_name($relation_name, $relation_obj) |
|
| 848 | - { |
|
| 849 | - if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
| 850 | - return strtolower($relation_name); |
|
| 851 | - } else { |
|
| 852 | - return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * Gets the one model object with the specified id for the specified model |
|
| 860 | - * |
|
| 861 | - * @param \EEM_Base $model |
|
| 862 | - * @param \WP_REST_Request $request |
|
| 863 | - * @return array|\WP_Error |
|
| 864 | - */ |
|
| 865 | - public function get_entity_from_model($model, $request) |
|
| 866 | - { |
|
| 867 | - $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
| 868 | - if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 869 | - $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 870 | - } |
|
| 871 | - $restricted_query_params = $query_params; |
|
| 872 | - $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
| 873 | - $this->_set_debug_info('model query params', $restricted_query_params); |
|
| 874 | - $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
| 875 | - if (! empty ($model_rows)) { |
|
| 876 | - return $this->create_entity_from_wpdb_result( |
|
| 877 | - $model, |
|
| 878 | - array_shift($model_rows), |
|
| 879 | - $request); |
|
| 880 | - } else { |
|
| 881 | - //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
|
| 882 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
| 883 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
| 884 | - if (! empty($model_rows_found_sans_restrictions)) { |
|
| 885 | - //you got shafted- it existed but we didn't want to tell you! |
|
| 886 | - return new \WP_Error( |
|
| 887 | - 'rest_user_cannot_read', |
|
| 888 | - sprintf( |
|
| 889 | - __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
| 890 | - strtolower($model->get_this_model_name()), |
|
| 891 | - Capabilities::get_missing_permissions_string( |
|
| 892 | - $model, |
|
| 893 | - $this->validate_context($request->get_param('caps'))) |
|
| 894 | - ), |
|
| 895 | - array('status' => 403) |
|
| 896 | - ); |
|
| 897 | - } else { |
|
| 898 | - //it's not you. It just doesn't exist |
|
| 899 | - return new \WP_Error( |
|
| 900 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
| 901 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
| 902 | - array('status' => 404) |
|
| 903 | - ); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * If a context is provided which isn't valid, maybe it was added in a future |
|
| 912 | - * version so just treat it as a default read |
|
| 913 | - * |
|
| 914 | - * @param string $context |
|
| 915 | - * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
|
| 916 | - */ |
|
| 917 | - public function validate_context($context) |
|
| 918 | - { |
|
| 919 | - if (! $context) { |
|
| 920 | - $context = \EEM_Base::caps_read; |
|
| 921 | - } |
|
| 922 | - $valid_contexts = \EEM_Base::valid_cap_contexts(); |
|
| 923 | - if (in_array($context, $valid_contexts)) { |
|
| 924 | - return $context; |
|
| 925 | - } else { |
|
| 926 | - return \EEM_Base::caps_read; |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * Verifies the passed in value is an allowable default where conditions value. |
|
| 934 | - * |
|
| 935 | - * @param $default_query_params |
|
| 936 | - * @return string |
|
| 937 | - */ |
|
| 938 | - public function validate_default_query_params($default_query_params) |
|
| 939 | - { |
|
| 940 | - $valid_default_where_conditions_for_api_calls = array( |
|
| 941 | - \EEM_Base::default_where_conditions_all, |
|
| 942 | - \EEM_Base::default_where_conditions_minimum_all, |
|
| 943 | - \EEM_Base::default_where_conditions_minimum_others, |
|
| 944 | - ); |
|
| 945 | - if (! $default_query_params) { |
|
| 946 | - $default_query_params = \EEM_Base::default_where_conditions_all; |
|
| 947 | - } |
|
| 948 | - if ( |
|
| 949 | - in_array( |
|
| 950 | - $default_query_params, |
|
| 951 | - $valid_default_where_conditions_for_api_calls, |
|
| 952 | - true |
|
| 953 | - ) |
|
| 954 | - ) { |
|
| 955 | - return $default_query_params; |
|
| 956 | - } else { |
|
| 957 | - return \EEM_Base::default_where_conditions_all; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * Translates API filter get parameter into $query_params array used by EEM_Base::get_all(). |
|
| 965 | - * Note: right now the query parameter keys for fields (and related fields) |
|
| 966 | - * can be left as-is, but it's quite possible this will change someday. |
|
| 967 | - * Also, this method's contents might be candidate for moving to Model_Data_Translator |
|
| 968 | - * |
|
| 969 | - * @param \EEM_Base $model |
|
| 970 | - * @param array $query_parameters from $_GET parameter @see Read:handle_request_get_all |
|
| 971 | - * @return array like what EEM_Base::get_all() expects or FALSE to indicate |
|
| 972 | - * that absolutely no results should be returned |
|
| 973 | - * @throws \EE_Error |
|
| 974 | - */ |
|
| 975 | - public function create_model_query_params($model, $query_parameters) |
|
| 976 | - { |
|
| 977 | - $model_query_params = array(); |
|
| 978 | - if (isset($query_parameters['where'])) { |
|
| 979 | - $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 980 | - $query_parameters['where'], |
|
| 981 | - $model, |
|
| 982 | - $this->get_model_version_info()->requested_version() |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - if (isset($query_parameters['order_by'])) { |
|
| 986 | - $order_by = $query_parameters['order_by']; |
|
| 987 | - } elseif (isset($query_parameters['orderby'])) { |
|
| 988 | - $order_by = $query_parameters['orderby']; |
|
| 989 | - } else { |
|
| 990 | - $order_by = null; |
|
| 991 | - } |
|
| 992 | - if ($order_by !== null) { |
|
| 993 | - if (is_array($order_by)) { |
|
| 994 | - $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
| 995 | - } else { |
|
| 996 | - //it's a single item |
|
| 997 | - $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
| 998 | - } |
|
| 999 | - $model_query_params['order_by'] = $order_by; |
|
| 1000 | - } |
|
| 1001 | - if (isset($query_parameters['group_by'])) { |
|
| 1002 | - $group_by = $query_parameters['group_by']; |
|
| 1003 | - } elseif (isset($query_parameters['groupby'])) { |
|
| 1004 | - $group_by = $query_parameters['groupby']; |
|
| 1005 | - } else { |
|
| 1006 | - $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
| 1007 | - } |
|
| 1008 | - //make sure they're all real names |
|
| 1009 | - if (is_array($group_by)) { |
|
| 1010 | - $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
| 1011 | - } |
|
| 1012 | - if ($group_by !== null) { |
|
| 1013 | - $model_query_params['group_by'] = $group_by; |
|
| 1014 | - } |
|
| 1015 | - if (isset($query_parameters['having'])) { |
|
| 1016 | - $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 1017 | - $query_parameters['having'], |
|
| 1018 | - $model, |
|
| 1019 | - $this->get_model_version_info()->requested_version() |
|
| 1020 | - ); |
|
| 1021 | - } |
|
| 1022 | - if (isset($query_parameters['order'])) { |
|
| 1023 | - $model_query_params['order'] = $query_parameters['order']; |
|
| 1024 | - } |
|
| 1025 | - if (isset($query_parameters['mine'])) { |
|
| 1026 | - $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
| 1027 | - } |
|
| 1028 | - if (isset($query_parameters['limit'])) { |
|
| 1029 | - //limit should be either a string like '23' or '23,43', or an array with two items in it |
|
| 1030 | - if (! is_array($query_parameters['limit'])) { |
|
| 1031 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
| 1032 | - } else { |
|
| 1033 | - $limit_array = $query_parameters['limit']; |
|
| 1034 | - } |
|
| 1035 | - $sanitized_limit = array(); |
|
| 1036 | - foreach ($limit_array as $key => $limit_part) { |
|
| 1037 | - if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 1038 | - throw new \EE_Error( |
|
| 1039 | - sprintf( |
|
| 1040 | - __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
|
| 1041 | - 'event_espresso'), |
|
| 1042 | - wp_json_encode($query_parameters['limit']) |
|
| 1043 | - ) |
|
| 1044 | - ); |
|
| 1045 | - } |
|
| 1046 | - $sanitized_limit[] = (int)$limit_part; |
|
| 1047 | - } |
|
| 1048 | - $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
| 1049 | - } else { |
|
| 1050 | - $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 1051 | - } |
|
| 1052 | - if (isset($query_parameters['caps'])) { |
|
| 1053 | - $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
| 1054 | - } else { |
|
| 1055 | - $model_query_params['caps'] = \EEM_Base::caps_read; |
|
| 1056 | - } |
|
| 1057 | - if (isset($query_parameters['default_where_conditions'])) { |
|
| 1058 | - $model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']); |
|
| 1059 | - } |
|
| 1060 | - return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Changes the REST-style query params for use in the models |
|
| 1067 | - * |
|
| 1068 | - * @deprecated |
|
| 1069 | - * @param \EEM_Base $model |
|
| 1070 | - * @param array $query_params sub-array from @see EEM_Base::get_all() |
|
| 1071 | - * @return array |
|
| 1072 | - */ |
|
| 1073 | - public function prepare_rest_query_params_key_for_models($model, $query_params) |
|
| 1074 | - { |
|
| 1075 | - $model_ready_query_params = array(); |
|
| 1076 | - foreach ($query_params as $key => $value) { |
|
| 1077 | - if (is_array($value)) { |
|
| 1078 | - $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
| 1079 | - } else { |
|
| 1080 | - $model_ready_query_params[$key] = $value; |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - return $model_ready_query_params; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - |
|
| 1088 | - /** |
|
| 1089 | - * @deprecated |
|
| 1090 | - * @param $model |
|
| 1091 | - * @param $query_params |
|
| 1092 | - * @return array |
|
| 1093 | - */ |
|
| 1094 | - public function prepare_rest_query_params_values_for_models($model, $query_params) |
|
| 1095 | - { |
|
| 1096 | - $model_ready_query_params = array(); |
|
| 1097 | - foreach ($query_params as $key => $value) { |
|
| 1098 | - if (is_array($value)) { |
|
| 1099 | - $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
| 1100 | - } else { |
|
| 1101 | - $model_ready_query_params[$key] = $value; |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - return $model_ready_query_params; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Explodes the string on commas, and only returns items with $prefix followed by a period. |
|
| 1111 | - * If no prefix is specified, returns items with no period. |
|
| 1112 | - * |
|
| 1113 | - * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' ) |
|
| 1114 | - * @param string $prefix "Event" or "foobar" |
|
| 1115 | - * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified |
|
| 1116 | - * we only return strings starting with that and a period; if no prefix was |
|
| 1117 | - * specified we return all items containing NO periods |
|
| 1118 | - */ |
|
| 1119 | - public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) |
|
| 1120 | - { |
|
| 1121 | - if (is_string($string_to_explode)) { |
|
| 1122 | - $exploded_contents = explode(',', $string_to_explode); |
|
| 1123 | - } else if (is_array($string_to_explode)) { |
|
| 1124 | - $exploded_contents = $string_to_explode; |
|
| 1125 | - } else { |
|
| 1126 | - $exploded_contents = array(); |
|
| 1127 | - } |
|
| 1128 | - //if the string was empty, we want an empty array |
|
| 1129 | - $exploded_contents = array_filter($exploded_contents); |
|
| 1130 | - $contents_with_prefix = array(); |
|
| 1131 | - foreach ($exploded_contents as $item) { |
|
| 1132 | - $item = trim($item); |
|
| 1133 | - //if no prefix was provided, so we look for items with no "." in them |
|
| 1134 | - if (! $prefix) { |
|
| 1135 | - //does this item have a period? |
|
| 1136 | - if (strpos($item, '.') === false) { |
|
| 1137 | - //if not, then its what we're looking for |
|
| 1138 | - $contents_with_prefix[] = $item; |
|
| 1139 | - } |
|
| 1140 | - } else if (strpos($item, $prefix . '.') === 0) { |
|
| 1141 | - //this item has the prefix and a period, grab it |
|
| 1142 | - $contents_with_prefix[] = substr( |
|
| 1143 | - $item, |
|
| 1144 | - strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
| 1145 | - ); |
|
| 1146 | - } else if ($item === $prefix) { |
|
| 1147 | - //this item is JUST the prefix |
|
| 1148 | - //so let's grab everything after, which is a blank string |
|
| 1149 | - $contents_with_prefix[] = ''; |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - return $contents_with_prefix; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with. |
|
| 1159 | - * Deprecated because its return values were really quite confusing- sometimes it returned |
|
| 1160 | - * an empty array (when the include string was blank or '*') or sometimes it returned |
|
| 1161 | - * array('*') (when you provided a model and a model of that kind was found). |
|
| 1162 | - * Parses the $include_string so we fetch all the field names relating to THIS model |
|
| 1163 | - * (ie have NO period in them), or for the provided model (ie start with the model |
|
| 1164 | - * name and then a period). |
|
| 1165 | - * @param string $include_string @see Read:handle_request_get_all |
|
| 1166 | - * @param string $model_name |
|
| 1167 | - * @return array of fields for this model. If $model_name is provided, then |
|
| 1168 | - * the fields for that model, with the model's name removed from each. |
|
| 1169 | - * If $include_string was blank or '*' returns an empty array |
|
| 1170 | - */ |
|
| 1171 | - public function extract_includes_for_this_model($include_string, $model_name = null) |
|
| 1172 | - { |
|
| 1173 | - if (is_array($include_string)) { |
|
| 1174 | - $include_string = implode(',', $include_string); |
|
| 1175 | - } |
|
| 1176 | - if ($include_string === '*' || $include_string === '') { |
|
| 1177 | - return array(); |
|
| 1178 | - } |
|
| 1179 | - $includes = explode(',', $include_string); |
|
| 1180 | - $extracted_fields_to_include = array(); |
|
| 1181 | - if ($model_name) { |
|
| 1182 | - foreach ($includes as $field_to_include) { |
|
| 1183 | - $field_to_include = trim($field_to_include); |
|
| 1184 | - if (strpos($field_to_include, $model_name . '.') === 0) { |
|
| 1185 | - //found the model name at the exact start |
|
| 1186 | - $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
| 1187 | - $extracted_fields_to_include[] = $field_sans_model_name; |
|
| 1188 | - } elseif ($field_to_include == $model_name) { |
|
| 1189 | - $extracted_fields_to_include[] = '*'; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - } else { |
|
| 1193 | - //look for ones with no period |
|
| 1194 | - foreach ($includes as $field_to_include) { |
|
| 1195 | - $field_to_include = trim($field_to_include); |
|
| 1196 | - if ( |
|
| 1197 | - strpos($field_to_include, '.') === false |
|
| 1198 | - && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
| 1199 | - ) { |
|
| 1200 | - $extracted_fields_to_include[] = $field_to_include; |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - } |
|
| 1204 | - return $extracted_fields_to_include; |
|
| 1205 | - } |
|
| 30 | + /** |
|
| 31 | + * @var Calculated_Model_Fields |
|
| 32 | + */ |
|
| 33 | + protected $_fields_calculator; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Read constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + parent::__construct(); |
|
| 43 | + $this->_fields_calculator = new Calculated_Model_Fields(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
| 50 | + * |
|
| 51 | + * @param \WP_REST_Request $request |
|
| 52 | + * @return \WP_REST_Response|\WP_Error |
|
| 53 | + */ |
|
| 54 | + public static function handle_request_get_all(\WP_REST_Request $request) |
|
| 55 | + { |
|
| 56 | + $controller = new Read(); |
|
| 57 | + try { |
|
| 58 | + $matches = $controller->parse_route( |
|
| 59 | + $request->get_route(), |
|
| 60 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 61 | + array('version', 'model') |
|
| 62 | + ); |
|
| 63 | + $controller->set_requested_version($matches['version']); |
|
| 64 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 65 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 66 | + return $controller->send_response( |
|
| 67 | + new \WP_Error( |
|
| 68 | + 'endpoint_parsing_error', |
|
| 69 | + sprintf( |
|
| 70 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 71 | + 'event_espresso'), |
|
| 72 | + $model_name_singular |
|
| 73 | + ) |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + return $controller->send_response( |
|
| 78 | + $controller->get_entities_from_model( |
|
| 79 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 80 | + $request |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + } catch (\Exception $e) { |
|
| 84 | + return $controller->send_response($e); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Prepares and returns schema for any OPTIONS request. |
|
| 91 | + * |
|
| 92 | + * @param string $model_name Something like `Event` or `Registration` |
|
| 93 | + * @param string $version The API endpoint version being used. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public static function handle_schema_request($model_name, $version) |
|
| 97 | + { |
|
| 98 | + $controller = new Read(); |
|
| 99 | + try { |
|
| 100 | + $controller->set_requested_version($version); |
|
| 101 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
| 102 | + return array(); |
|
| 103 | + } |
|
| 104 | + //get the model for this version |
|
| 105 | + $model = $controller->get_model_version_info()->load_model($model_name); |
|
| 106 | + $model_schema = new JsonModelSchema($model); |
|
| 107 | + return $model_schema->getModelSchemaForRelations( |
|
| 108 | + $controller->get_model_version_info()->relation_settings($model), |
|
| 109 | + $controller->_add_extra_fields_to_schema( |
|
| 110 | + $model, |
|
| 111 | + $model_schema->getModelSchemaForFields( |
|
| 112 | + $controller->get_model_version_info()->fields_on_model_in_this_version($model), |
|
| 113 | + $model_schema->getInitialSchemaStructure() |
|
| 114 | + ) |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | + } catch (\Exception $e) { |
|
| 118 | + return array(); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Adds additional fields to the schema |
|
| 125 | + * The REST API returns a GMT value field for each datetime field in the resource. Thus the description about this |
|
| 126 | + * needs to be added to the schema. |
|
| 127 | + * |
|
| 128 | + * @param \EEM_Base $model |
|
| 129 | + * @param string $schema |
|
| 130 | + */ |
|
| 131 | + protected function _add_extra_fields_to_schema(\EEM_Base $model, $schema) |
|
| 132 | + { |
|
| 133 | + foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field) { |
|
| 134 | + if ($field instanceof EE_Datetime_Field) { |
|
| 135 | + $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
| 136 | + //modify the description |
|
| 137 | + $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
| 138 | + esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
|
| 139 | + $field->get_nicename() |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return $schema; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Used to figure out the route from the request when a `WP_REST_Request` object is not available |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + protected function get_route_from_request() { |
|
| 154 | + if (isset($GLOBALS['wp']) |
|
| 155 | + && $GLOBALS['wp'] instanceof \WP |
|
| 156 | + && isset($GLOBALS['wp']->query_vars['rest_route'] ) |
|
| 157 | + ) { |
|
| 158 | + return $GLOBALS['wp']->query_vars['rest_route']; |
|
| 159 | + } else { |
|
| 160 | + return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Gets a single entity related to the model indicated in the path and its id |
|
| 168 | + * |
|
| 169 | + * @param \WP_REST_Request $request |
|
| 170 | + * @return \WP_REST_Response|\WP_Error |
|
| 171 | + */ |
|
| 172 | + public static function handle_request_get_one(\WP_REST_Request $request) |
|
| 173 | + { |
|
| 174 | + $controller = new Read(); |
|
| 175 | + try { |
|
| 176 | + $matches = $controller->parse_route( |
|
| 177 | + $request->get_route(), |
|
| 178 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 179 | + array('version', 'model', 'id')); |
|
| 180 | + $controller->set_requested_version($matches['version']); |
|
| 181 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 182 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 183 | + return $controller->send_response( |
|
| 184 | + new \WP_Error( |
|
| 185 | + 'endpoint_parsing_error', |
|
| 186 | + sprintf( |
|
| 187 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 188 | + 'event_espresso'), |
|
| 189 | + $model_name_singular |
|
| 190 | + ) |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + return $controller->send_response( |
|
| 195 | + $controller->get_entity_from_model( |
|
| 196 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 197 | + $request |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + } catch (\Exception $e) { |
|
| 201 | + return $controller->send_response($e); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Gets all the related entities (or if its a belongs-to relation just the one) |
|
| 209 | + * to the item with the given id |
|
| 210 | + * |
|
| 211 | + * @param \WP_REST_Request $request |
|
| 212 | + * @return \WP_REST_Response|\WP_Error |
|
| 213 | + */ |
|
| 214 | + public static function handle_request_get_related(\WP_REST_Request $request) |
|
| 215 | + { |
|
| 216 | + $controller = new Read(); |
|
| 217 | + try { |
|
| 218 | + $matches = $controller->parse_route( |
|
| 219 | + $request->get_route(), |
|
| 220 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 221 | + array('version', 'model', 'id', 'related_model') |
|
| 222 | + ); |
|
| 223 | + $controller->set_requested_version($matches['version']); |
|
| 224 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 225 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 226 | + return $controller->send_response( |
|
| 227 | + new \WP_Error( |
|
| 228 | + 'endpoint_parsing_error', |
|
| 229 | + sprintf( |
|
| 230 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 231 | + 'event_espresso'), |
|
| 232 | + $main_model_name_singular |
|
| 233 | + ) |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
| 238 | + //assume the related model name is plural and try to find the model's name |
|
| 239 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
| 240 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 241 | + //so the word didn't singularize well. Maybe that's just because it's a singular word? |
|
| 242 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
| 243 | + } |
|
| 244 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 245 | + return $controller->send_response( |
|
| 246 | + new \WP_Error( |
|
| 247 | + 'endpoint_parsing_error', |
|
| 248 | + sprintf( |
|
| 249 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
| 250 | + 'event_espresso'), |
|
| 251 | + $related_model_name_singular |
|
| 252 | + ) |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + return $controller->send_response( |
|
| 257 | + $controller->get_entities_from_relation( |
|
| 258 | + $request->get_param('id'), |
|
| 259 | + $main_model->related_settings_for($related_model_name_singular), |
|
| 260 | + $request |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } catch (\Exception $e) { |
|
| 264 | + return $controller->send_response($e); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Gets a collection for the given model and filters |
|
| 272 | + * |
|
| 273 | + * @param \EEM_Base $model |
|
| 274 | + * @param \WP_REST_Request $request |
|
| 275 | + * @return array|\WP_Error |
|
| 276 | + */ |
|
| 277 | + public function get_entities_from_model($model, $request) |
|
| 278 | + { |
|
| 279 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
| 280 | + if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 281 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 282 | + return new \WP_Error( |
|
| 283 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
| 284 | + sprintf( |
|
| 285 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
| 286 | + $model_name_plural, |
|
| 287 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
| 288 | + ), |
|
| 289 | + array('status' => 403) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + if (! $request->get_header('no_rest_headers')) { |
|
| 293 | + $this->_set_headers_from_query_params($model, $query_params); |
|
| 294 | + } |
|
| 295 | + /** @type array $results */ |
|
| 296 | + $results = $model->get_all_wpdb_results($query_params); |
|
| 297 | + $nice_results = array(); |
|
| 298 | + foreach ($results as $result) { |
|
| 299 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
| 300 | + $model, |
|
| 301 | + $result, |
|
| 302 | + $request |
|
| 303 | + ); |
|
| 304 | + } |
|
| 305 | + return $nice_results; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param array $primary_model_query_params query params for finding the item from which |
|
| 312 | + * relations will be based |
|
| 313 | + * @param \EE_Model_Relation_Base $relation |
|
| 314 | + * @param \WP_REST_Request $request |
|
| 315 | + * @return \WP_Error|array |
|
| 316 | + */ |
|
| 317 | + protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) |
|
| 318 | + { |
|
| 319 | + $context = $this->validate_context($request->get_param('caps')); |
|
| 320 | + $model = $relation->get_this_model(); |
|
| 321 | + $related_model = $relation->get_other_model(); |
|
| 322 | + if (! isset($primary_model_query_params[0])) { |
|
| 323 | + $primary_model_query_params[0] = array(); |
|
| 324 | + } |
|
| 325 | + //check if they can access the 1st model object |
|
| 326 | + $primary_model_query_params = array( |
|
| 327 | + 0 => $primary_model_query_params[0], |
|
| 328 | + 'limit' => 1, |
|
| 329 | + ); |
|
| 330 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 331 | + $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
| 332 | + } |
|
| 333 | + $restricted_query_params = $primary_model_query_params; |
|
| 334 | + $restricted_query_params['caps'] = $context; |
|
| 335 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
| 336 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
| 337 | + if ( |
|
| 338 | + ! ( |
|
| 339 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
| 340 | + && $model->exists($restricted_query_params) |
|
| 341 | + ) |
|
| 342 | + ) { |
|
| 343 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 344 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
| 345 | + } else { |
|
| 346 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
| 347 | + } |
|
| 348 | + return new \WP_Error( |
|
| 349 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
| 350 | + sprintf( |
|
| 351 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', |
|
| 352 | + 'event_espresso'), |
|
| 353 | + $related_model_name_maybe_plural, |
|
| 354 | + $relation->get_this_model()->get_this_model_name(), |
|
| 355 | + implode( |
|
| 356 | + ',', |
|
| 357 | + array_keys( |
|
| 358 | + Capabilities::get_missing_permissions($related_model, $context) |
|
| 359 | + ) |
|
| 360 | + ) |
|
| 361 | + ), |
|
| 362 | + array('status' => 403) |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
| 366 | + foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
| 367 | + $query_params[0][$relation->get_this_model()->get_this_model_name() |
|
| 368 | + . '.' |
|
| 369 | + . $where_condition_key] = $where_condition_value; |
|
| 370 | + } |
|
| 371 | + $query_params['default_where_conditions'] = 'none'; |
|
| 372 | + $query_params['caps'] = $context; |
|
| 373 | + if (! $request->get_header('no_rest_headers')) { |
|
| 374 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
| 375 | + } |
|
| 376 | + /** @type array $results */ |
|
| 377 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
| 378 | + $nice_results = array(); |
|
| 379 | + foreach ($results as $result) { |
|
| 380 | + $nice_result = $this->create_entity_from_wpdb_result( |
|
| 381 | + $relation->get_other_model(), |
|
| 382 | + $result, |
|
| 383 | + $request |
|
| 384 | + ); |
|
| 385 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
| 386 | + //put the unusual stuff (properties from the HABTM relation) first, and make sure |
|
| 387 | + //if there are conflicts we prefer the properties from the main model |
|
| 388 | + $join_model_result = $this->create_entity_from_wpdb_result( |
|
| 389 | + $relation->get_join_model(), |
|
| 390 | + $result, |
|
| 391 | + $request |
|
| 392 | + ); |
|
| 393 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
| 394 | + //but keep the meta stuff from the main model |
|
| 395 | + if (isset($nice_result['meta'])) { |
|
| 396 | + $joined_result['meta'] = $nice_result['meta']; |
|
| 397 | + } |
|
| 398 | + $nice_result = $joined_result; |
|
| 399 | + } |
|
| 400 | + $nice_results[] = $nice_result; |
|
| 401 | + } |
|
| 402 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 403 | + return array_shift($nice_results); |
|
| 404 | + } else { |
|
| 405 | + return $nice_results; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets the collection for given relation object |
|
| 413 | + * The same as Read::get_entities_from_model(), except if the relation |
|
| 414 | + * is a HABTM relation, in which case it merges any non-foreign-key fields from |
|
| 415 | + * the join-model-object into the results |
|
| 416 | + * |
|
| 417 | + * @param string $id the ID of the thing we are fetching related stuff from |
|
| 418 | + * @param \EE_Model_Relation_Base $relation |
|
| 419 | + * @param \WP_REST_Request $request |
|
| 420 | + * @return array|\WP_Error |
|
| 421 | + * @throws \EE_Error |
|
| 422 | + */ |
|
| 423 | + public function get_entities_from_relation($id, $relation, $request) |
|
| 424 | + { |
|
| 425 | + if (! $relation->get_this_model()->has_primary_key_field()) { |
|
| 426 | + throw new \EE_Error( |
|
| 427 | + sprintf( |
|
| 428 | + __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
|
| 429 | + 'event_espresso'), |
|
| 430 | + $relation->get_this_model()->get_this_model_name() |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $this->_get_entities_from_relation( |
|
| 435 | + array( |
|
| 436 | + array( |
|
| 437 | + $relation->get_this_model()->primary_key_name() => $id, |
|
| 438 | + ), |
|
| 439 | + ), |
|
| 440 | + $relation, |
|
| 441 | + $request |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Sets the headers that are based on the model and query params, |
|
| 449 | + * like the total records. This should only be called on the original request |
|
| 450 | + * from the client, not on subsequent internal |
|
| 451 | + * |
|
| 452 | + * @param \EEM_Base $model |
|
| 453 | + * @param array $query_params |
|
| 454 | + * @return void |
|
| 455 | + */ |
|
| 456 | + protected function _set_headers_from_query_params($model, $query_params) |
|
| 457 | + { |
|
| 458 | + $this->_set_debug_info('model query params', $query_params); |
|
| 459 | + $this->_set_debug_info('missing caps', |
|
| 460 | + Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
| 461 | + //normally the limit to a 2-part array, where the 2nd item is the limit |
|
| 462 | + if (! isset($query_params['limit'])) { |
|
| 463 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 464 | + } |
|
| 465 | + if (is_array($query_params['limit'])) { |
|
| 466 | + $limit_parts = $query_params['limit']; |
|
| 467 | + } else { |
|
| 468 | + $limit_parts = explode(',', $query_params['limit']); |
|
| 469 | + if (count($limit_parts) == 1) { |
|
| 470 | + $limit_parts = array(0, $limit_parts[0]); |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + //remove the group by and having parts of the query, as those will |
|
| 474 | + //make the sql query return an array of values, instead of just a single value |
|
| 475 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
| 476 | + $count = $model->count($query_params, null, true); |
|
| 477 | + $pages = $count / $limit_parts[1]; |
|
| 478 | + $this->_set_response_header('Total', $count, false); |
|
| 479 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
| 480 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Changes database results into REST API entities |
|
| 487 | + * |
|
| 488 | + * @param \EEM_Base $model |
|
| 489 | + * @param array $db_row like results from $wpdb->get_results() |
|
| 490 | + * @param \WP_REST_Request $rest_request |
|
| 491 | + * @param string $deprecated no longer used |
|
| 492 | + * @return array ready for being converted into json for sending to client |
|
| 493 | + */ |
|
| 494 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
|
| 495 | + { |
|
| 496 | + if (! $rest_request instanceof \WP_REST_Request) { |
|
| 497 | + //ok so this was called in the old style, where the 3rd arg was |
|
| 498 | + //$include, and the 4th arg was $context |
|
| 499 | + //now setup the request just to avoid fatal errors, although we won't be able |
|
| 500 | + //to truly make use of it because it's kinda devoid of info |
|
| 501 | + $rest_request = new \WP_REST_Request(); |
|
| 502 | + $rest_request->set_param('include', $rest_request); |
|
| 503 | + $rest_request->set_param('caps', $deprecated); |
|
| 504 | + } |
|
| 505 | + if ($rest_request->get_param('caps') == null) { |
|
| 506 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
| 507 | + } |
|
| 508 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
| 509 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
| 510 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
| 511 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
| 512 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
| 513 | + $entity_array = apply_filters( |
|
| 514 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
| 515 | + $entity_array, |
|
| 516 | + $model, |
|
| 517 | + $rest_request->get_param('caps'), |
|
| 518 | + $rest_request, |
|
| 519 | + $this |
|
| 520 | + ); |
|
| 521 | + $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
|
| 522 | + $entity_array, |
|
| 523 | + $model, |
|
| 524 | + $rest_request->get_param('caps'), |
|
| 525 | + $this->get_model_version_info(), |
|
| 526 | + $model->get_index_primary_key_string( |
|
| 527 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 528 | + ) |
|
| 529 | + ); |
|
| 530 | + $this->_set_debug_info( |
|
| 531 | + 'inaccessible fields', |
|
| 532 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
| 533 | + ); |
|
| 534 | + return apply_filters( |
|
| 535 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
|
| 536 | + $result_without_inaccessible_fields, |
|
| 537 | + $model, |
|
| 538 | + $rest_request->get_param('caps') |
|
| 539 | + ); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Creates a REST entity array (JSON object we're going to return in the response, but |
|
| 546 | + * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry), |
|
| 547 | + * from $wpdb->get_row( $sql, ARRAY_A) |
|
| 548 | + * |
|
| 549 | + * @param \EEM_Base $model |
|
| 550 | + * @param array $db_row |
|
| 551 | + * @return array entity mostly ready for converting to JSON and sending in the response |
|
| 552 | + */ |
|
| 553 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) |
|
| 554 | + { |
|
| 555 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
| 556 | + $result = array_intersect_key($result, |
|
| 557 | + $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
| 558 | + foreach ($result as $field_name => $raw_field_value) { |
|
| 559 | + $field_obj = $model->field_settings_for($field_name); |
|
| 560 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
| 561 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
| 562 | + unset($result[$field_name]); |
|
| 563 | + } elseif ( |
|
| 564 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
| 565 | + ) { |
|
| 566 | + $result[$field_name] = array( |
|
| 567 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 568 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
| 569 | + ); |
|
| 570 | + } elseif ( |
|
| 571 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
| 572 | + ) { |
|
| 573 | + $result[$field_name] = array( |
|
| 574 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 575 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
| 576 | + ); |
|
| 577 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 578 | + if ($field_value instanceof \DateTime) { |
|
| 579 | + $timezone = $field_value->getTimezone(); |
|
| 580 | + $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
| 581 | + $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 582 | + $field_obj, |
|
| 583 | + $field_value, |
|
| 584 | + $this->get_model_version_info()->requested_version() |
|
| 585 | + ); |
|
| 586 | + $field_value->setTimezone($timezone); |
|
| 587 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 588 | + $field_obj, |
|
| 589 | + $field_value, |
|
| 590 | + $this->get_model_version_info()->requested_version() |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + } else { |
|
| 594 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 595 | + $field_obj, |
|
| 596 | + $field_obj->prepare_for_get($field_value), |
|
| 597 | + $this->get_model_version_info()->requested_version() |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + return $result; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Adds a few extra fields to the entity response |
|
| 608 | + * |
|
| 609 | + * @param \EEM_Base $model |
|
| 610 | + * @param array $db_row |
|
| 611 | + * @param array $entity_array |
|
| 612 | + * @return array modified entity |
|
| 613 | + */ |
|
| 614 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) |
|
| 615 | + { |
|
| 616 | + if ($model instanceof \EEM_CPT_Base) { |
|
| 617 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
| 618 | + } |
|
| 619 | + return $entity_array; |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Gets links we want to add to the response |
|
| 626 | + * |
|
| 627 | + * @global \WP_REST_Server $wp_rest_server |
|
| 628 | + * @param \EEM_Base $model |
|
| 629 | + * @param array $db_row |
|
| 630 | + * @param array $entity_array |
|
| 631 | + * @return array the _links item in the entity |
|
| 632 | + */ |
|
| 633 | + protected function _get_entity_links($model, $db_row, $entity_array) |
|
| 634 | + { |
|
| 635 | + //add basic links |
|
| 636 | + $links = array(); |
|
| 637 | + if ($model->has_primary_key_field()) { |
|
| 638 | + $links['self'] = array( |
|
| 639 | + array( |
|
| 640 | + 'href' => $this->get_versioned_link_to( |
|
| 641 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 642 | + . '/' |
|
| 643 | + . $entity_array[$model->primary_key_name()] |
|
| 644 | + ), |
|
| 645 | + ), |
|
| 646 | + ); |
|
| 647 | + } |
|
| 648 | + $links['collection'] = array( |
|
| 649 | + array( |
|
| 650 | + 'href' => $this->get_versioned_link_to( |
|
| 651 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 652 | + ), |
|
| 653 | + ), |
|
| 654 | + ); |
|
| 655 | + //add links to related models |
|
| 656 | + if ($model->has_primary_key_field()) { |
|
| 657 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 658 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
| 659 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
| 660 | + array( |
|
| 661 | + 'href' => $this->get_versioned_link_to( |
|
| 662 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 663 | + . '/' |
|
| 664 | + . $entity_array[$model->primary_key_name()] |
|
| 665 | + . '/' |
|
| 666 | + . $related_model_part |
|
| 667 | + ), |
|
| 668 | + 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
| 669 | + ), |
|
| 670 | + ); |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + return $links; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Adds the included models indicated in the request to the entity provided |
|
| 680 | + * |
|
| 681 | + * @param \EEM_Base $model |
|
| 682 | + * @param \WP_REST_Request $rest_request |
|
| 683 | + * @param array $entity_array |
|
| 684 | + * @param array $db_row |
|
| 685 | + * @return array the modified entity |
|
| 686 | + */ |
|
| 687 | + protected function _include_requested_models( |
|
| 688 | + \EEM_Base $model, |
|
| 689 | + \WP_REST_Request $rest_request, |
|
| 690 | + $entity_array, |
|
| 691 | + $db_row = array() |
|
| 692 | + ) { |
|
| 693 | + //if $db_row not included, hope the entity array has what we need |
|
| 694 | + if (! $db_row) { |
|
| 695 | + $db_row = $entity_array; |
|
| 696 | + } |
|
| 697 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
| 698 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
| 699 | + //if they passed in * or didn't specify any includes, return everything |
|
| 700 | + if (! in_array('*', $includes_for_this_model) |
|
| 701 | + && ! empty($includes_for_this_model) |
|
| 702 | + ) { |
|
| 703 | + if ($model->has_primary_key_field()) { |
|
| 704 | + //always include the primary key. ya just gotta know that at least |
|
| 705 | + $includes_for_this_model[] = $model->primary_key_name(); |
|
| 706 | + } |
|
| 707 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
| 708 | + $includes_for_this_model[] = '_calculated_fields'; |
|
| 709 | + } |
|
| 710 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
| 711 | + } |
|
| 712 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
| 713 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
| 714 | + $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
|
| 715 | + $rest_request->get_param('include'), |
|
| 716 | + $relation_name |
|
| 717 | + ); |
|
| 718 | + $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
|
| 719 | + $rest_request->get_param('calculate'), |
|
| 720 | + $relation_name |
|
| 721 | + ); |
|
| 722 | + //did they specify they wanted to include a related model, or |
|
| 723 | + //specific fields from a related model? |
|
| 724 | + //or did they specify to calculate a field from a related model? |
|
| 725 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
| 726 | + //if so, we should include at least some part of the related model |
|
| 727 | + $pretend_related_request = new \WP_REST_Request(); |
|
| 728 | + $pretend_related_request->set_query_params( |
|
| 729 | + array( |
|
| 730 | + 'caps' => $rest_request->get_param('caps'), |
|
| 731 | + 'include' => $related_fields_to_include, |
|
| 732 | + 'calculate' => $related_fields_to_calculate, |
|
| 733 | + ) |
|
| 734 | + ); |
|
| 735 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
| 736 | + $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
|
| 737 | + $model->get_index_primary_key_string( |
|
| 738 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 739 | + ) |
|
| 740 | + ); |
|
| 741 | + $related_results = $this->_get_entities_from_relation( |
|
| 742 | + $primary_model_query_params, |
|
| 743 | + $relation_obj, |
|
| 744 | + $pretend_related_request |
|
| 745 | + ); |
|
| 746 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results |
|
| 747 | + instanceof |
|
| 748 | + \WP_Error |
|
| 749 | + ? null |
|
| 750 | + : $related_results; |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + return $entity_array; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Returns a new array with all the names of models removed. Eg |
|
| 760 | + * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' ) |
|
| 761 | + * |
|
| 762 | + * @param array $arr |
|
| 763 | + * @return array |
|
| 764 | + */ |
|
| 765 | + private function _remove_model_names_from_array($arr) |
|
| 766 | + { |
|
| 767 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Gets the calculated fields for the response |
|
| 774 | + * |
|
| 775 | + * @param \EEM_Base $model |
|
| 776 | + * @param array $wpdb_row |
|
| 777 | + * @param \WP_REST_Request $rest_request |
|
| 778 | + * @return \stdClass the _calculations item in the entity |
|
| 779 | + */ |
|
| 780 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) |
|
| 781 | + { |
|
| 782 | + $calculated_fields = $this->explode_and_get_items_prefixed_with( |
|
| 783 | + $rest_request->get_param('calculate'), |
|
| 784 | + '' |
|
| 785 | + ); |
|
| 786 | + //note: setting calculate=* doesn't do anything |
|
| 787 | + $calculated_fields_to_return = new \stdClass(); |
|
| 788 | + foreach ($calculated_fields as $field_to_calculate) { |
|
| 789 | + try { |
|
| 790 | + $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
|
| 791 | + null, |
|
| 792 | + $this->_fields_calculator->retrieve_calculated_field_value( |
|
| 793 | + $model, |
|
| 794 | + $field_to_calculate, |
|
| 795 | + $wpdb_row, |
|
| 796 | + $rest_request, |
|
| 797 | + $this |
|
| 798 | + ), |
|
| 799 | + $this->get_model_version_info()->requested_version() |
|
| 800 | + ); |
|
| 801 | + } catch (Rest_Exception $e) { |
|
| 802 | + //if we don't have permission to read it, just leave it out. but let devs know about the problem |
|
| 803 | + $this->_set_response_header( |
|
| 804 | + 'Notices-Field-Calculation-Errors[' |
|
| 805 | + . $e->get_string_code() |
|
| 806 | + . '][' |
|
| 807 | + . $model->get_this_model_name() |
|
| 808 | + . '][' |
|
| 809 | + . $field_to_calculate |
|
| 810 | + . ']', |
|
| 811 | + $e->getMessage(), |
|
| 812 | + true |
|
| 813 | + ); |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + return $calculated_fields_to_return; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Gets the full URL to the resource, taking the requested version into account |
|
| 823 | + * |
|
| 824 | + * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
|
| 825 | + * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
|
| 826 | + */ |
|
| 827 | + public function get_versioned_link_to($link_part_after_version_and_slash) |
|
| 828 | + { |
|
| 829 | + return rest_url( |
|
| 830 | + \EED_Core_Rest_Api::ee_api_namespace |
|
| 831 | + . $this->get_model_version_info()->requested_version() |
|
| 832 | + . '/' |
|
| 833 | + . $link_part_after_version_and_slash |
|
| 834 | + ); |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * Gets the correct lowercase name for the relation in the API according |
|
| 841 | + * to the relation's type |
|
| 842 | + * |
|
| 843 | + * @param string $relation_name |
|
| 844 | + * @param \EE_Model_Relation_Base $relation_obj |
|
| 845 | + * @return string |
|
| 846 | + */ |
|
| 847 | + public static function get_related_entity_name($relation_name, $relation_obj) |
|
| 848 | + { |
|
| 849 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
| 850 | + return strtolower($relation_name); |
|
| 851 | + } else { |
|
| 852 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Gets the one model object with the specified id for the specified model |
|
| 860 | + * |
|
| 861 | + * @param \EEM_Base $model |
|
| 862 | + * @param \WP_REST_Request $request |
|
| 863 | + * @return array|\WP_Error |
|
| 864 | + */ |
|
| 865 | + public function get_entity_from_model($model, $request) |
|
| 866 | + { |
|
| 867 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
| 868 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 869 | + $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
| 870 | + } |
|
| 871 | + $restricted_query_params = $query_params; |
|
| 872 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
| 873 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
| 874 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
| 875 | + if (! empty ($model_rows)) { |
|
| 876 | + return $this->create_entity_from_wpdb_result( |
|
| 877 | + $model, |
|
| 878 | + array_shift($model_rows), |
|
| 879 | + $request); |
|
| 880 | + } else { |
|
| 881 | + //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
|
| 882 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
| 883 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
| 884 | + if (! empty($model_rows_found_sans_restrictions)) { |
|
| 885 | + //you got shafted- it existed but we didn't want to tell you! |
|
| 886 | + return new \WP_Error( |
|
| 887 | + 'rest_user_cannot_read', |
|
| 888 | + sprintf( |
|
| 889 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
| 890 | + strtolower($model->get_this_model_name()), |
|
| 891 | + Capabilities::get_missing_permissions_string( |
|
| 892 | + $model, |
|
| 893 | + $this->validate_context($request->get_param('caps'))) |
|
| 894 | + ), |
|
| 895 | + array('status' => 403) |
|
| 896 | + ); |
|
| 897 | + } else { |
|
| 898 | + //it's not you. It just doesn't exist |
|
| 899 | + return new \WP_Error( |
|
| 900 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
| 901 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
| 902 | + array('status' => 404) |
|
| 903 | + ); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * If a context is provided which isn't valid, maybe it was added in a future |
|
| 912 | + * version so just treat it as a default read |
|
| 913 | + * |
|
| 914 | + * @param string $context |
|
| 915 | + * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
|
| 916 | + */ |
|
| 917 | + public function validate_context($context) |
|
| 918 | + { |
|
| 919 | + if (! $context) { |
|
| 920 | + $context = \EEM_Base::caps_read; |
|
| 921 | + } |
|
| 922 | + $valid_contexts = \EEM_Base::valid_cap_contexts(); |
|
| 923 | + if (in_array($context, $valid_contexts)) { |
|
| 924 | + return $context; |
|
| 925 | + } else { |
|
| 926 | + return \EEM_Base::caps_read; |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * Verifies the passed in value is an allowable default where conditions value. |
|
| 934 | + * |
|
| 935 | + * @param $default_query_params |
|
| 936 | + * @return string |
|
| 937 | + */ |
|
| 938 | + public function validate_default_query_params($default_query_params) |
|
| 939 | + { |
|
| 940 | + $valid_default_where_conditions_for_api_calls = array( |
|
| 941 | + \EEM_Base::default_where_conditions_all, |
|
| 942 | + \EEM_Base::default_where_conditions_minimum_all, |
|
| 943 | + \EEM_Base::default_where_conditions_minimum_others, |
|
| 944 | + ); |
|
| 945 | + if (! $default_query_params) { |
|
| 946 | + $default_query_params = \EEM_Base::default_where_conditions_all; |
|
| 947 | + } |
|
| 948 | + if ( |
|
| 949 | + in_array( |
|
| 950 | + $default_query_params, |
|
| 951 | + $valid_default_where_conditions_for_api_calls, |
|
| 952 | + true |
|
| 953 | + ) |
|
| 954 | + ) { |
|
| 955 | + return $default_query_params; |
|
| 956 | + } else { |
|
| 957 | + return \EEM_Base::default_where_conditions_all; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * Translates API filter get parameter into $query_params array used by EEM_Base::get_all(). |
|
| 965 | + * Note: right now the query parameter keys for fields (and related fields) |
|
| 966 | + * can be left as-is, but it's quite possible this will change someday. |
|
| 967 | + * Also, this method's contents might be candidate for moving to Model_Data_Translator |
|
| 968 | + * |
|
| 969 | + * @param \EEM_Base $model |
|
| 970 | + * @param array $query_parameters from $_GET parameter @see Read:handle_request_get_all |
|
| 971 | + * @return array like what EEM_Base::get_all() expects or FALSE to indicate |
|
| 972 | + * that absolutely no results should be returned |
|
| 973 | + * @throws \EE_Error |
|
| 974 | + */ |
|
| 975 | + public function create_model_query_params($model, $query_parameters) |
|
| 976 | + { |
|
| 977 | + $model_query_params = array(); |
|
| 978 | + if (isset($query_parameters['where'])) { |
|
| 979 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 980 | + $query_parameters['where'], |
|
| 981 | + $model, |
|
| 982 | + $this->get_model_version_info()->requested_version() |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + if (isset($query_parameters['order_by'])) { |
|
| 986 | + $order_by = $query_parameters['order_by']; |
|
| 987 | + } elseif (isset($query_parameters['orderby'])) { |
|
| 988 | + $order_by = $query_parameters['orderby']; |
|
| 989 | + } else { |
|
| 990 | + $order_by = null; |
|
| 991 | + } |
|
| 992 | + if ($order_by !== null) { |
|
| 993 | + if (is_array($order_by)) { |
|
| 994 | + $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
| 995 | + } else { |
|
| 996 | + //it's a single item |
|
| 997 | + $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
| 998 | + } |
|
| 999 | + $model_query_params['order_by'] = $order_by; |
|
| 1000 | + } |
|
| 1001 | + if (isset($query_parameters['group_by'])) { |
|
| 1002 | + $group_by = $query_parameters['group_by']; |
|
| 1003 | + } elseif (isset($query_parameters['groupby'])) { |
|
| 1004 | + $group_by = $query_parameters['groupby']; |
|
| 1005 | + } else { |
|
| 1006 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
| 1007 | + } |
|
| 1008 | + //make sure they're all real names |
|
| 1009 | + if (is_array($group_by)) { |
|
| 1010 | + $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
| 1011 | + } |
|
| 1012 | + if ($group_by !== null) { |
|
| 1013 | + $model_query_params['group_by'] = $group_by; |
|
| 1014 | + } |
|
| 1015 | + if (isset($query_parameters['having'])) { |
|
| 1016 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 1017 | + $query_parameters['having'], |
|
| 1018 | + $model, |
|
| 1019 | + $this->get_model_version_info()->requested_version() |
|
| 1020 | + ); |
|
| 1021 | + } |
|
| 1022 | + if (isset($query_parameters['order'])) { |
|
| 1023 | + $model_query_params['order'] = $query_parameters['order']; |
|
| 1024 | + } |
|
| 1025 | + if (isset($query_parameters['mine'])) { |
|
| 1026 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
| 1027 | + } |
|
| 1028 | + if (isset($query_parameters['limit'])) { |
|
| 1029 | + //limit should be either a string like '23' or '23,43', or an array with two items in it |
|
| 1030 | + if (! is_array($query_parameters['limit'])) { |
|
| 1031 | + $limit_array = explode(',', (string)$query_parameters['limit']); |
|
| 1032 | + } else { |
|
| 1033 | + $limit_array = $query_parameters['limit']; |
|
| 1034 | + } |
|
| 1035 | + $sanitized_limit = array(); |
|
| 1036 | + foreach ($limit_array as $key => $limit_part) { |
|
| 1037 | + if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 1038 | + throw new \EE_Error( |
|
| 1039 | + sprintf( |
|
| 1040 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
|
| 1041 | + 'event_espresso'), |
|
| 1042 | + wp_json_encode($query_parameters['limit']) |
|
| 1043 | + ) |
|
| 1044 | + ); |
|
| 1045 | + } |
|
| 1046 | + $sanitized_limit[] = (int)$limit_part; |
|
| 1047 | + } |
|
| 1048 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
| 1049 | + } else { |
|
| 1050 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 1051 | + } |
|
| 1052 | + if (isset($query_parameters['caps'])) { |
|
| 1053 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
| 1054 | + } else { |
|
| 1055 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
| 1056 | + } |
|
| 1057 | + if (isset($query_parameters['default_where_conditions'])) { |
|
| 1058 | + $model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']); |
|
| 1059 | + } |
|
| 1060 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Changes the REST-style query params for use in the models |
|
| 1067 | + * |
|
| 1068 | + * @deprecated |
|
| 1069 | + * @param \EEM_Base $model |
|
| 1070 | + * @param array $query_params sub-array from @see EEM_Base::get_all() |
|
| 1071 | + * @return array |
|
| 1072 | + */ |
|
| 1073 | + public function prepare_rest_query_params_key_for_models($model, $query_params) |
|
| 1074 | + { |
|
| 1075 | + $model_ready_query_params = array(); |
|
| 1076 | + foreach ($query_params as $key => $value) { |
|
| 1077 | + if (is_array($value)) { |
|
| 1078 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
| 1079 | + } else { |
|
| 1080 | + $model_ready_query_params[$key] = $value; |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + return $model_ready_query_params; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * @deprecated |
|
| 1090 | + * @param $model |
|
| 1091 | + * @param $query_params |
|
| 1092 | + * @return array |
|
| 1093 | + */ |
|
| 1094 | + public function prepare_rest_query_params_values_for_models($model, $query_params) |
|
| 1095 | + { |
|
| 1096 | + $model_ready_query_params = array(); |
|
| 1097 | + foreach ($query_params as $key => $value) { |
|
| 1098 | + if (is_array($value)) { |
|
| 1099 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
| 1100 | + } else { |
|
| 1101 | + $model_ready_query_params[$key] = $value; |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + return $model_ready_query_params; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Explodes the string on commas, and only returns items with $prefix followed by a period. |
|
| 1111 | + * If no prefix is specified, returns items with no period. |
|
| 1112 | + * |
|
| 1113 | + * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' ) |
|
| 1114 | + * @param string $prefix "Event" or "foobar" |
|
| 1115 | + * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified |
|
| 1116 | + * we only return strings starting with that and a period; if no prefix was |
|
| 1117 | + * specified we return all items containing NO periods |
|
| 1118 | + */ |
|
| 1119 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) |
|
| 1120 | + { |
|
| 1121 | + if (is_string($string_to_explode)) { |
|
| 1122 | + $exploded_contents = explode(',', $string_to_explode); |
|
| 1123 | + } else if (is_array($string_to_explode)) { |
|
| 1124 | + $exploded_contents = $string_to_explode; |
|
| 1125 | + } else { |
|
| 1126 | + $exploded_contents = array(); |
|
| 1127 | + } |
|
| 1128 | + //if the string was empty, we want an empty array |
|
| 1129 | + $exploded_contents = array_filter($exploded_contents); |
|
| 1130 | + $contents_with_prefix = array(); |
|
| 1131 | + foreach ($exploded_contents as $item) { |
|
| 1132 | + $item = trim($item); |
|
| 1133 | + //if no prefix was provided, so we look for items with no "." in them |
|
| 1134 | + if (! $prefix) { |
|
| 1135 | + //does this item have a period? |
|
| 1136 | + if (strpos($item, '.') === false) { |
|
| 1137 | + //if not, then its what we're looking for |
|
| 1138 | + $contents_with_prefix[] = $item; |
|
| 1139 | + } |
|
| 1140 | + } else if (strpos($item, $prefix . '.') === 0) { |
|
| 1141 | + //this item has the prefix and a period, grab it |
|
| 1142 | + $contents_with_prefix[] = substr( |
|
| 1143 | + $item, |
|
| 1144 | + strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
| 1145 | + ); |
|
| 1146 | + } else if ($item === $prefix) { |
|
| 1147 | + //this item is JUST the prefix |
|
| 1148 | + //so let's grab everything after, which is a blank string |
|
| 1149 | + $contents_with_prefix[] = ''; |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + return $contents_with_prefix; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with. |
|
| 1159 | + * Deprecated because its return values were really quite confusing- sometimes it returned |
|
| 1160 | + * an empty array (when the include string was blank or '*') or sometimes it returned |
|
| 1161 | + * array('*') (when you provided a model and a model of that kind was found). |
|
| 1162 | + * Parses the $include_string so we fetch all the field names relating to THIS model |
|
| 1163 | + * (ie have NO period in them), or for the provided model (ie start with the model |
|
| 1164 | + * name and then a period). |
|
| 1165 | + * @param string $include_string @see Read:handle_request_get_all |
|
| 1166 | + * @param string $model_name |
|
| 1167 | + * @return array of fields for this model. If $model_name is provided, then |
|
| 1168 | + * the fields for that model, with the model's name removed from each. |
|
| 1169 | + * If $include_string was blank or '*' returns an empty array |
|
| 1170 | + */ |
|
| 1171 | + public function extract_includes_for_this_model($include_string, $model_name = null) |
|
| 1172 | + { |
|
| 1173 | + if (is_array($include_string)) { |
|
| 1174 | + $include_string = implode(',', $include_string); |
|
| 1175 | + } |
|
| 1176 | + if ($include_string === '*' || $include_string === '') { |
|
| 1177 | + return array(); |
|
| 1178 | + } |
|
| 1179 | + $includes = explode(',', $include_string); |
|
| 1180 | + $extracted_fields_to_include = array(); |
|
| 1181 | + if ($model_name) { |
|
| 1182 | + foreach ($includes as $field_to_include) { |
|
| 1183 | + $field_to_include = trim($field_to_include); |
|
| 1184 | + if (strpos($field_to_include, $model_name . '.') === 0) { |
|
| 1185 | + //found the model name at the exact start |
|
| 1186 | + $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
| 1187 | + $extracted_fields_to_include[] = $field_sans_model_name; |
|
| 1188 | + } elseif ($field_to_include == $model_name) { |
|
| 1189 | + $extracted_fields_to_include[] = '*'; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + } else { |
|
| 1193 | + //look for ones with no period |
|
| 1194 | + foreach ($includes as $field_to_include) { |
|
| 1195 | + $field_to_include = trim($field_to_include); |
|
| 1196 | + if ( |
|
| 1197 | + strpos($field_to_include, '.') === false |
|
| 1198 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
| 1199 | + ) { |
|
| 1200 | + $extracted_fields_to_include[] = $field_to_include; |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + return $extracted_fields_to_include; |
|
| 1205 | + } |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use EventEspresso\core\entities\models\JsonModelSchema; |
| 9 | 9 | use EE_Datetime_Field; |
| 10 | 10 | |
| 11 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 12 | 12 | exit('No direct script access allowed'); |
| 13 | 13 | } |
| 14 | 14 | |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | try { |
| 58 | 58 | $matches = $controller->parse_route( |
| 59 | 59 | $request->get_route(), |
| 60 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 60 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
| 61 | 61 | array('version', 'model') |
| 62 | 62 | ); |
| 63 | 63 | $controller->set_requested_version($matches['version']); |
| 64 | 64 | $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
| 65 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 65 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 66 | 66 | return $controller->send_response( |
| 67 | 67 | new \WP_Error( |
| 68 | 68 | 'endpoint_parsing_error', |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $controller = new Read(); |
| 99 | 99 | try { |
| 100 | 100 | $controller->set_requested_version($version); |
| 101 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
| 101 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
| 102 | 102 | return array(); |
| 103 | 103 | } |
| 104 | 104 | //get the model for this version |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field) { |
| 134 | 134 | if ($field instanceof EE_Datetime_Field) { |
| 135 | - $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
| 135 | + $schema['properties'][$field_name.'_gmt'] = $field->getSchema(); |
|
| 136 | 136 | //modify the description |
| 137 | - $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
| 137 | + $schema['properties'][$field_name.'_gmt']['description'] = sprintf( |
|
| 138 | 138 | esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
| 139 | 139 | $field->get_nicename() |
| 140 | 140 | ); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | protected function get_route_from_request() { |
| 154 | 154 | if (isset($GLOBALS['wp']) |
| 155 | 155 | && $GLOBALS['wp'] instanceof \WP |
| 156 | - && isset($GLOBALS['wp']->query_vars['rest_route'] ) |
|
| 156 | + && isset($GLOBALS['wp']->query_vars['rest_route']) |
|
| 157 | 157 | ) { |
| 158 | 158 | return $GLOBALS['wp']->query_vars['rest_route']; |
| 159 | 159 | } else { |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | try { |
| 176 | 176 | $matches = $controller->parse_route( |
| 177 | 177 | $request->get_route(), |
| 178 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 178 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
| 179 | 179 | array('version', 'model', 'id')); |
| 180 | 180 | $controller->set_requested_version($matches['version']); |
| 181 | 181 | $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
| 182 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 182 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 183 | 183 | return $controller->send_response( |
| 184 | 184 | new \WP_Error( |
| 185 | 185 | 'endpoint_parsing_error', |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | try { |
| 218 | 218 | $matches = $controller->parse_route( |
| 219 | 219 | $request->get_route(), |
| 220 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 220 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
| 221 | 221 | array('version', 'model', 'id', 'related_model') |
| 222 | 222 | ); |
| 223 | 223 | $controller->set_requested_version($matches['version']); |
| 224 | 224 | $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
| 225 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 225 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 226 | 226 | return $controller->send_response( |
| 227 | 227 | new \WP_Error( |
| 228 | 228 | 'endpoint_parsing_error', |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
| 238 | 238 | //assume the related model name is plural and try to find the model's name |
| 239 | 239 | $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
| 240 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 240 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 241 | 241 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
| 242 | 242 | $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
| 243 | 243 | } |
| 244 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 244 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 245 | 245 | return $controller->send_response( |
| 246 | 246 | new \WP_Error( |
| 247 | 247 | 'endpoint_parsing_error', |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | public function get_entities_from_model($model, $request) |
| 278 | 278 | { |
| 279 | 279 | $query_params = $this->create_model_query_params($model, $request->get_params()); |
| 280 | - if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 280 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 281 | 281 | $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
| 282 | 282 | return new \WP_Error( |
| 283 | 283 | sprintf('rest_%s_cannot_list', $model_name_plural), |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | array('status' => 403) |
| 290 | 290 | ); |
| 291 | 291 | } |
| 292 | - if (! $request->get_header('no_rest_headers')) { |
|
| 292 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 293 | 293 | $this->_set_headers_from_query_params($model, $query_params); |
| 294 | 294 | } |
| 295 | 295 | /** @type array $results */ |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | $context = $this->validate_context($request->get_param('caps')); |
| 320 | 320 | $model = $relation->get_this_model(); |
| 321 | 321 | $related_model = $relation->get_other_model(); |
| 322 | - if (! isset($primary_model_query_params[0])) { |
|
| 322 | + if ( ! isset($primary_model_query_params[0])) { |
|
| 323 | 323 | $primary_model_query_params[0] = array(); |
| 324 | 324 | } |
| 325 | 325 | //check if they can access the 1st model object |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | $query_params['default_where_conditions'] = 'none'; |
| 372 | 372 | $query_params['caps'] = $context; |
| 373 | - if (! $request->get_header('no_rest_headers')) { |
|
| 373 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 374 | 374 | $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
| 375 | 375 | } |
| 376 | 376 | /** @type array $results */ |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | public function get_entities_from_relation($id, $relation, $request) |
| 424 | 424 | { |
| 425 | - if (! $relation->get_this_model()->has_primary_key_field()) { |
|
| 425 | + if ( ! $relation->get_this_model()->has_primary_key_field()) { |
|
| 426 | 426 | throw new \EE_Error( |
| 427 | 427 | sprintf( |
| 428 | 428 | __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $this->_set_debug_info('missing caps', |
| 460 | 460 | Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
| 461 | 461 | //normally the limit to a 2-part array, where the 2nd item is the limit |
| 462 | - if (! isset($query_params['limit'])) { |
|
| 462 | + if ( ! isset($query_params['limit'])) { |
|
| 463 | 463 | $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
| 464 | 464 | } |
| 465 | 465 | if (is_array($query_params['limit'])) { |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | */ |
| 494 | 494 | public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
| 495 | 495 | { |
| 496 | - if (! $rest_request instanceof \WP_REST_Request) { |
|
| 496 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
| 497 | 497 | //ok so this was called in the old style, where the 3rd arg was |
| 498 | 498 | //$include, and the 4th arg was $context |
| 499 | 499 | //now setup the request just to avoid fatal errors, although we won't be able |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | if ($field_value instanceof \DateTime) { |
| 579 | 579 | $timezone = $field_value->getTimezone(); |
| 580 | 580 | $field_value->setTimezone(new \DateTimeZone('UTC')); |
| 581 | - $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 581 | + $result[$field_name.'_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 582 | 582 | $field_obj, |
| 583 | 583 | $field_value, |
| 584 | 584 | $this->get_model_version_info()->requested_version() |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | if ($model->has_primary_key_field()) { |
| 657 | 657 | foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
| 658 | 658 | $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
| 659 | - $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
| 659 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
| 660 | 660 | array( |
| 661 | 661 | 'href' => $this->get_versioned_link_to( |
| 662 | 662 | \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
@@ -691,13 +691,13 @@ discard block |
||
| 691 | 691 | $db_row = array() |
| 692 | 692 | ) { |
| 693 | 693 | //if $db_row not included, hope the entity array has what we need |
| 694 | - if (! $db_row) { |
|
| 694 | + if ( ! $db_row) { |
|
| 695 | 695 | $db_row = $entity_array; |
| 696 | 696 | } |
| 697 | 697 | $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
| 698 | 698 | $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
| 699 | 699 | //if they passed in * or didn't specify any includes, return everything |
| 700 | - if (! in_array('*', $includes_for_this_model) |
|
| 700 | + if ( ! in_array('*', $includes_for_this_model) |
|
| 701 | 701 | && ! empty($includes_for_this_model) |
| 702 | 702 | ) { |
| 703 | 703 | if ($model->has_primary_key_field()) { |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
| 873 | 873 | $this->_set_debug_info('model query params', $restricted_query_params); |
| 874 | 874 | $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
| 875 | - if (! empty ($model_rows)) { |
|
| 875 | + if ( ! empty ($model_rows)) { |
|
| 876 | 876 | return $this->create_entity_from_wpdb_result( |
| 877 | 877 | $model, |
| 878 | 878 | array_shift($model_rows), |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
| 882 | 882 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
| 883 | 883 | $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
| 884 | - if (! empty($model_rows_found_sans_restrictions)) { |
|
| 884 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
| 885 | 885 | //you got shafted- it existed but we didn't want to tell you! |
| 886 | 886 | return new \WP_Error( |
| 887 | 887 | 'rest_user_cannot_read', |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | */ |
| 917 | 917 | public function validate_context($context) |
| 918 | 918 | { |
| 919 | - if (! $context) { |
|
| 919 | + if ( ! $context) { |
|
| 920 | 920 | $context = \EEM_Base::caps_read; |
| 921 | 921 | } |
| 922 | 922 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | \EEM_Base::default_where_conditions_minimum_all, |
| 943 | 943 | \EEM_Base::default_where_conditions_minimum_others, |
| 944 | 944 | ); |
| 945 | - if (! $default_query_params) { |
|
| 945 | + if ( ! $default_query_params) { |
|
| 946 | 946 | $default_query_params = \EEM_Base::default_where_conditions_all; |
| 947 | 947 | } |
| 948 | 948 | if ( |
@@ -1027,14 +1027,14 @@ discard block |
||
| 1027 | 1027 | } |
| 1028 | 1028 | if (isset($query_parameters['limit'])) { |
| 1029 | 1029 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
| 1030 | - if (! is_array($query_parameters['limit'])) { |
|
| 1031 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
| 1030 | + if ( ! is_array($query_parameters['limit'])) { |
|
| 1031 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
| 1032 | 1032 | } else { |
| 1033 | 1033 | $limit_array = $query_parameters['limit']; |
| 1034 | 1034 | } |
| 1035 | 1035 | $sanitized_limit = array(); |
| 1036 | 1036 | foreach ($limit_array as $key => $limit_part) { |
| 1037 | - if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 1037 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 1038 | 1038 | throw new \EE_Error( |
| 1039 | 1039 | sprintf( |
| 1040 | 1040 | __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | ) |
| 1044 | 1044 | ); |
| 1045 | 1045 | } |
| 1046 | - $sanitized_limit[] = (int)$limit_part; |
|
| 1046 | + $sanitized_limit[] = (int) $limit_part; |
|
| 1047 | 1047 | } |
| 1048 | 1048 | $model_query_params['limit'] = implode(',', $sanitized_limit); |
| 1049 | 1049 | } else { |
@@ -1131,17 +1131,17 @@ discard block |
||
| 1131 | 1131 | foreach ($exploded_contents as $item) { |
| 1132 | 1132 | $item = trim($item); |
| 1133 | 1133 | //if no prefix was provided, so we look for items with no "." in them |
| 1134 | - if (! $prefix) { |
|
| 1134 | + if ( ! $prefix) { |
|
| 1135 | 1135 | //does this item have a period? |
| 1136 | 1136 | if (strpos($item, '.') === false) { |
| 1137 | 1137 | //if not, then its what we're looking for |
| 1138 | 1138 | $contents_with_prefix[] = $item; |
| 1139 | 1139 | } |
| 1140 | - } else if (strpos($item, $prefix . '.') === 0) { |
|
| 1140 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
| 1141 | 1141 | //this item has the prefix and a period, grab it |
| 1142 | 1142 | $contents_with_prefix[] = substr( |
| 1143 | 1143 | $item, |
| 1144 | - strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
| 1144 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
| 1145 | 1145 | ); |
| 1146 | 1146 | } else if ($item === $prefix) { |
| 1147 | 1147 | //this item is JUST the prefix |
@@ -1181,9 +1181,9 @@ discard block |
||
| 1181 | 1181 | if ($model_name) { |
| 1182 | 1182 | foreach ($includes as $field_to_include) { |
| 1183 | 1183 | $field_to_include = trim($field_to_include); |
| 1184 | - if (strpos($field_to_include, $model_name . '.') === 0) { |
|
| 1184 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
| 1185 | 1185 | //found the model name at the exact start |
| 1186 | - $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
| 1186 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
| 1187 | 1187 | $extracted_fields_to_include[] = $field_sans_model_name; |
| 1188 | 1188 | } elseif ($field_to_include == $model_name) { |
| 1189 | 1189 | $extracted_fields_to_include[] = '*'; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.26.rc.012'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.26.rc.012'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - /** |
|
| 197 | - * espresso_plugin_activation |
|
| 198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | - */ |
|
| 200 | - function espresso_plugin_activation() |
|
| 201 | - { |
|
| 202 | - update_option('ee_espresso_activation', true); |
|
| 203 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + /** |
|
| 197 | + * espresso_plugin_activation |
|
| 198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | + */ |
|
| 200 | + function espresso_plugin_activation() |
|
| 201 | + { |
|
| 202 | + update_option('ee_espresso_activation', true); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | - /** |
|
| 207 | - * espresso_load_error_handling |
|
| 208 | - * this function loads EE's class for handling exceptions and errors |
|
| 209 | - */ |
|
| 210 | - function espresso_load_error_handling() |
|
| 211 | - { |
|
| 212 | - // load debugging tools |
|
| 213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | - EEH_Debug_Tools::instance(); |
|
| 216 | - } |
|
| 217 | - // load error handling |
|
| 218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | - } else { |
|
| 221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | - } |
|
| 223 | - } |
|
| 205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | + /** |
|
| 207 | + * espresso_load_error_handling |
|
| 208 | + * this function loads EE's class for handling exceptions and errors |
|
| 209 | + */ |
|
| 210 | + function espresso_load_error_handling() |
|
| 211 | + { |
|
| 212 | + // load debugging tools |
|
| 213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | + EEH_Debug_Tools::instance(); |
|
| 216 | + } |
|
| 217 | + // load error handling |
|
| 218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | + } else { |
|
| 221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * espresso_load_required |
|
| 227 | - * given a class name and path, this function will load that file or throw an exception |
|
| 228 | - * |
|
| 229 | - * @param string $classname |
|
| 230 | - * @param string $full_path_to_file |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | - { |
|
| 235 | - static $error_handling_loaded = false; |
|
| 236 | - if ( ! $error_handling_loaded) { |
|
| 237 | - espresso_load_error_handling(); |
|
| 238 | - $error_handling_loaded = true; |
|
| 239 | - } |
|
| 240 | - if (is_readable($full_path_to_file)) { |
|
| 241 | - require_once($full_path_to_file); |
|
| 242 | - } else { |
|
| 243 | - throw new EE_Error ( |
|
| 244 | - sprintf( |
|
| 245 | - esc_html__( |
|
| 246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ), |
|
| 249 | - $classname |
|
| 250 | - ) |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - } |
|
| 225 | + /** |
|
| 226 | + * espresso_load_required |
|
| 227 | + * given a class name and path, this function will load that file or throw an exception |
|
| 228 | + * |
|
| 229 | + * @param string $classname |
|
| 230 | + * @param string $full_path_to_file |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | + { |
|
| 235 | + static $error_handling_loaded = false; |
|
| 236 | + if ( ! $error_handling_loaded) { |
|
| 237 | + espresso_load_error_handling(); |
|
| 238 | + $error_handling_loaded = true; |
|
| 239 | + } |
|
| 240 | + if (is_readable($full_path_to_file)) { |
|
| 241 | + require_once($full_path_to_file); |
|
| 242 | + } else { |
|
| 243 | + throw new EE_Error ( |
|
| 244 | + sprintf( |
|
| 245 | + esc_html__( |
|
| 246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ), |
|
| 249 | + $classname |
|
| 250 | + ) |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | - new EE_Bootstrap(); |
|
| 259 | - } |
|
| 255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | + new EE_Bootstrap(); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 262 | - /** |
|
| 263 | - * deactivate_plugin |
|
| 264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | - * |
|
| 266 | - * @access public |
|
| 267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | - { |
|
| 272 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | - } |
|
| 275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | - deactivate_plugins($plugin_basename); |
|
| 277 | - } |
|
| 262 | + /** |
|
| 263 | + * deactivate_plugin |
|
| 264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | + * |
|
| 266 | + * @access public |
|
| 267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | + { |
|
| 272 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | + } |
|
| 275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | + deactivate_plugins($plugin_basename); |
|
| 277 | + } |
|
| 278 | 278 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -28,580 +28,580 @@ discard block |
||
| 28 | 28 | class Registration_Form_Admin_Page extends EE_Admin_Page |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * _question |
|
| 33 | - * holds the specific question object for the question details screen |
|
| 34 | - * |
|
| 35 | - * @var EE_Question $_question |
|
| 36 | - */ |
|
| 37 | - protected $_question; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * _question_group |
|
| 41 | - * holds the specific question group object for the question group details screen |
|
| 42 | - * |
|
| 43 | - * @var EE_Question_Group $_question_group |
|
| 44 | - */ |
|
| 45 | - protected $_question_group; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - *_question_model EEM_Question model instance (for queries) |
|
| 49 | - * |
|
| 50 | - * @var EEM_Question $_question_model ; |
|
| 51 | - */ |
|
| 52 | - protected $_question_model; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * _question_group_model EEM_Question_group instance (for queries) |
|
| 56 | - * |
|
| 57 | - * @var EEM_Question_Group $_question_group_model |
|
| 58 | - */ |
|
| 59 | - protected $_question_group_model; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @Constructor |
|
| 64 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 65 | - * @access public |
|
| 66 | - */ |
|
| 67 | - public function __construct($routing = true) |
|
| 68 | - { |
|
| 69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 71 | - $this->_question_model = EEM_Question::instance(); |
|
| 72 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
| 73 | - parent::__construct($routing); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - protected function _init_page_props() |
|
| 78 | - { |
|
| 79 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
| 80 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
| 81 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
| 82 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - protected function _ajax_hooks() |
|
| 87 | - { |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - protected function _define_page_props() |
|
| 92 | - { |
|
| 93 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
| 94 | - $this->_labels = array( |
|
| 95 | - 'buttons' => array( |
|
| 96 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
| 97 | - ), |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - *_set_page_routes |
|
| 104 | - */ |
|
| 105 | - protected function _set_page_routes() |
|
| 106 | - { |
|
| 107 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 108 | - $this->_page_routes = array( |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_questions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_questions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'edit_question' => array( |
|
| 115 | - 'func' => '_edit_question', |
|
| 116 | - 'capability' => 'ee_edit_question', |
|
| 117 | - 'obj_id' => $qst_id, |
|
| 118 | - 'args' => array('edit'), |
|
| 119 | - ), |
|
| 120 | - |
|
| 121 | - 'question_groups' => array( |
|
| 122 | - 'func' => '_questions_groups_preview', |
|
| 123 | - 'capability' => 'ee_read_question_groups', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'update_question' => array( |
|
| 127 | - 'func' => '_insert_or_update_question', |
|
| 128 | - 'args' => array('new_question' => false), |
|
| 129 | - 'capability' => 'ee_edit_question', |
|
| 130 | - 'obj_id' => $qst_id, |
|
| 131 | - 'noheader' => true, |
|
| 132 | - ), |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - protected function _set_page_config() |
|
| 138 | - { |
|
| 139 | - $this->_page_config = array( |
|
| 140 | - 'default' => array( |
|
| 141 | - 'nav' => array( |
|
| 142 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
| 143 | - 'order' => 10, |
|
| 144 | - ), |
|
| 145 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
| 146 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 147 | - 'help_tabs' => array( |
|
| 148 | - 'registration_form_questions_overview_help_tab' => array( |
|
| 149 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
| 150 | - 'filename' => 'registration_form_questions_overview', |
|
| 151 | - ), |
|
| 152 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
| 153 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
| 154 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
| 155 | - ), |
|
| 156 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
| 157 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
| 158 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
| 159 | - ), |
|
| 160 | - ), |
|
| 161 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
| 162 | - 'require_nonce' => false, |
|
| 163 | - 'qtips' => array( |
|
| 164 | - 'EE_Registration_Form_Tips', |
|
| 165 | - )/**/ |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - 'question_groups' => array( |
|
| 169 | - 'nav' => array( |
|
| 170 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 171 | - 'order' => 20, |
|
| 172 | - ), |
|
| 173 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 174 | - 'help_tabs' => array( |
|
| 175 | - 'registration_form_question_groups_help_tab' => array( |
|
| 176 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 177 | - 'filename' => 'registration_form_question_groups', |
|
| 178 | - ), |
|
| 179 | - ), |
|
| 180 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 181 | - 'require_nonce' => false, |
|
| 182 | - ), |
|
| 183 | - |
|
| 184 | - 'edit_question' => array( |
|
| 185 | - 'nav' => array( |
|
| 186 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
| 187 | - 'order' => 15, |
|
| 188 | - 'persistent' => false, |
|
| 189 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
| 190 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 191 | - ), |
|
| 192 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 193 | - 'help_tabs' => array( |
|
| 194 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 195 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
| 196 | - 'filename' => 'registration_form_edit_question', |
|
| 197 | - ), |
|
| 198 | - ), |
|
| 199 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
| 200 | - 'require_nonce' => false, |
|
| 201 | - ), |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - protected function _add_screen_options() |
|
| 207 | - { |
|
| 208 | - //todo |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - protected function _add_screen_options_default() |
|
| 212 | - { |
|
| 213 | - $page_title = $this->_admin_page_title; |
|
| 214 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
| 215 | - $this->_per_page_screen_option(); |
|
| 216 | - $this->_admin_page_title = $page_title; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - protected function _add_screen_options_question_groups() |
|
| 220 | - { |
|
| 221 | - $page_title = $this->_admin_page_title; |
|
| 222 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
| 223 | - $this->_per_page_screen_option(); |
|
| 224 | - $this->_admin_page_title = $page_title; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - //none of the below group are currently used for Event Categories |
|
| 228 | - protected function _add_feature_pointers() |
|
| 229 | - { |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public function load_scripts_styles() |
|
| 233 | - { |
|
| 234 | - wp_register_style('espresso_registration', |
|
| 235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | - wp_enqueue_style('espresso_registration'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public function admin_init() |
|
| 240 | - { |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function admin_notices() |
|
| 244 | - { |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - public function admin_footer_scripts() |
|
| 248 | - { |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - public function load_scripts_styles_default() |
|
| 253 | - { |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - public function load_scripts_styles_add_question() |
|
| 258 | - { |
|
| 259 | - $this->load_scripts_styles_forms(); |
|
| 260 | - wp_register_script('espresso_registration_form_single', |
|
| 261 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 262 | - EVENT_ESPRESSO_VERSION, true); |
|
| 263 | - wp_enqueue_script('espresso_registration_form_single'); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - public function load_scripts_styles_edit_question() |
|
| 267 | - { |
|
| 268 | - $this->load_scripts_styles_forms(); |
|
| 269 | - wp_register_script('espresso_registration_form_single', |
|
| 270 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 271 | - EVENT_ESPRESSO_VERSION, true); |
|
| 272 | - wp_enqueue_script('espresso_registration_form_single'); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - public function recaptcha_info_help_tab() |
|
| 277 | - { |
|
| 278 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 279 | - EEH_Template::display_template($template, array()); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - public function load_scripts_styles_forms() |
|
| 284 | - { |
|
| 285 | - //styles |
|
| 286 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 287 | - //scripts |
|
| 288 | - wp_enqueue_script('ee_admin_js'); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - protected function _set_list_table_views_default() |
|
| 293 | - { |
|
| 294 | - $this->_views = array( |
|
| 295 | - 'all' => array( |
|
| 296 | - 'slug' => 'all', |
|
| 297 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 298 | - 'count' => 0, |
|
| 31 | + /** |
|
| 32 | + * _question |
|
| 33 | + * holds the specific question object for the question details screen |
|
| 34 | + * |
|
| 35 | + * @var EE_Question $_question |
|
| 36 | + */ |
|
| 37 | + protected $_question; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * _question_group |
|
| 41 | + * holds the specific question group object for the question group details screen |
|
| 42 | + * |
|
| 43 | + * @var EE_Question_Group $_question_group |
|
| 44 | + */ |
|
| 45 | + protected $_question_group; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + *_question_model EEM_Question model instance (for queries) |
|
| 49 | + * |
|
| 50 | + * @var EEM_Question $_question_model ; |
|
| 51 | + */ |
|
| 52 | + protected $_question_model; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * _question_group_model EEM_Question_group instance (for queries) |
|
| 56 | + * |
|
| 57 | + * @var EEM_Question_Group $_question_group_model |
|
| 58 | + */ |
|
| 59 | + protected $_question_group_model; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @Constructor |
|
| 64 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 65 | + * @access public |
|
| 66 | + */ |
|
| 67 | + public function __construct($routing = true) |
|
| 68 | + { |
|
| 69 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 71 | + $this->_question_model = EEM_Question::instance(); |
|
| 72 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
| 73 | + parent::__construct($routing); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + protected function _init_page_props() |
|
| 78 | + { |
|
| 79 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
| 80 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
| 81 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
| 82 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + protected function _ajax_hooks() |
|
| 87 | + { |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + protected function _define_page_props() |
|
| 92 | + { |
|
| 93 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
| 94 | + $this->_labels = array( |
|
| 95 | + 'buttons' => array( |
|
| 96 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
| 97 | + ), |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + *_set_page_routes |
|
| 104 | + */ |
|
| 105 | + protected function _set_page_routes() |
|
| 106 | + { |
|
| 107 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 108 | + $this->_page_routes = array( |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_questions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_questions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'edit_question' => array( |
|
| 115 | + 'func' => '_edit_question', |
|
| 116 | + 'capability' => 'ee_edit_question', |
|
| 117 | + 'obj_id' => $qst_id, |
|
| 118 | + 'args' => array('edit'), |
|
| 119 | + ), |
|
| 120 | + |
|
| 121 | + 'question_groups' => array( |
|
| 122 | + 'func' => '_questions_groups_preview', |
|
| 123 | + 'capability' => 'ee_read_question_groups', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'update_question' => array( |
|
| 127 | + 'func' => '_insert_or_update_question', |
|
| 128 | + 'args' => array('new_question' => false), |
|
| 129 | + 'capability' => 'ee_edit_question', |
|
| 130 | + 'obj_id' => $qst_id, |
|
| 131 | + 'noheader' => true, |
|
| 132 | + ), |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + protected function _set_page_config() |
|
| 138 | + { |
|
| 139 | + $this->_page_config = array( |
|
| 140 | + 'default' => array( |
|
| 141 | + 'nav' => array( |
|
| 142 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
| 143 | + 'order' => 10, |
|
| 144 | + ), |
|
| 145 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
| 146 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 147 | + 'help_tabs' => array( |
|
| 148 | + 'registration_form_questions_overview_help_tab' => array( |
|
| 149 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
| 150 | + 'filename' => 'registration_form_questions_overview', |
|
| 151 | + ), |
|
| 152 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
| 153 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
| 154 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
| 155 | + ), |
|
| 156 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
| 157 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
| 158 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
| 159 | + ), |
|
| 160 | + ), |
|
| 161 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
| 162 | + 'require_nonce' => false, |
|
| 163 | + 'qtips' => array( |
|
| 164 | + 'EE_Registration_Form_Tips', |
|
| 165 | + )/**/ |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + 'question_groups' => array( |
|
| 169 | + 'nav' => array( |
|
| 170 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 171 | + 'order' => 20, |
|
| 172 | + ), |
|
| 173 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 174 | + 'help_tabs' => array( |
|
| 175 | + 'registration_form_question_groups_help_tab' => array( |
|
| 176 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 177 | + 'filename' => 'registration_form_question_groups', |
|
| 178 | + ), |
|
| 179 | + ), |
|
| 180 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 181 | + 'require_nonce' => false, |
|
| 182 | + ), |
|
| 183 | + |
|
| 184 | + 'edit_question' => array( |
|
| 185 | + 'nav' => array( |
|
| 186 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
| 187 | + 'order' => 15, |
|
| 188 | + 'persistent' => false, |
|
| 189 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
| 190 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 191 | + ), |
|
| 192 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 193 | + 'help_tabs' => array( |
|
| 194 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 195 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
| 196 | + 'filename' => 'registration_form_edit_question', |
|
| 197 | + ), |
|
| 198 | + ), |
|
| 199 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
| 200 | + 'require_nonce' => false, |
|
| 201 | + ), |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + protected function _add_screen_options() |
|
| 207 | + { |
|
| 208 | + //todo |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + protected function _add_screen_options_default() |
|
| 212 | + { |
|
| 213 | + $page_title = $this->_admin_page_title; |
|
| 214 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
| 215 | + $this->_per_page_screen_option(); |
|
| 216 | + $this->_admin_page_title = $page_title; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + protected function _add_screen_options_question_groups() |
|
| 220 | + { |
|
| 221 | + $page_title = $this->_admin_page_title; |
|
| 222 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
| 223 | + $this->_per_page_screen_option(); |
|
| 224 | + $this->_admin_page_title = $page_title; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + //none of the below group are currently used for Event Categories |
|
| 228 | + protected function _add_feature_pointers() |
|
| 229 | + { |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public function load_scripts_styles() |
|
| 233 | + { |
|
| 234 | + wp_register_style('espresso_registration', |
|
| 235 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | + wp_enqueue_style('espresso_registration'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public function admin_init() |
|
| 240 | + { |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function admin_notices() |
|
| 244 | + { |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + public function admin_footer_scripts() |
|
| 248 | + { |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + public function load_scripts_styles_default() |
|
| 253 | + { |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + public function load_scripts_styles_add_question() |
|
| 258 | + { |
|
| 259 | + $this->load_scripts_styles_forms(); |
|
| 260 | + wp_register_script('espresso_registration_form_single', |
|
| 261 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 262 | + EVENT_ESPRESSO_VERSION, true); |
|
| 263 | + wp_enqueue_script('espresso_registration_form_single'); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + public function load_scripts_styles_edit_question() |
|
| 267 | + { |
|
| 268 | + $this->load_scripts_styles_forms(); |
|
| 269 | + wp_register_script('espresso_registration_form_single', |
|
| 270 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 271 | + EVENT_ESPRESSO_VERSION, true); |
|
| 272 | + wp_enqueue_script('espresso_registration_form_single'); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + public function recaptcha_info_help_tab() |
|
| 277 | + { |
|
| 278 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 279 | + EEH_Template::display_template($template, array()); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + public function load_scripts_styles_forms() |
|
| 284 | + { |
|
| 285 | + //styles |
|
| 286 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 287 | + //scripts |
|
| 288 | + wp_enqueue_script('ee_admin_js'); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + protected function _set_list_table_views_default() |
|
| 293 | + { |
|
| 294 | + $this->_views = array( |
|
| 295 | + 'all' => array( |
|
| 296 | + 'slug' => 'all', |
|
| 297 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 298 | + 'count' => 0, |
|
| 299 | 299 | // 'bulk_action' => array( |
| 300 | 300 | // 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
| 301 | 301 | // ) |
| 302 | - ), |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 306 | - 'espresso_registration_form_trash_questions') |
|
| 307 | - ) { |
|
| 308 | - $this->_views['trash'] = array( |
|
| 309 | - 'slug' => 'trash', |
|
| 310 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 311 | - 'count' => 0, |
|
| 302 | + ), |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 306 | + 'espresso_registration_form_trash_questions') |
|
| 307 | + ) { |
|
| 308 | + $this->_views['trash'] = array( |
|
| 309 | + 'slug' => 'trash', |
|
| 310 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 311 | + 'count' => 0, |
|
| 312 | 312 | // 'bulk_action' => array( |
| 313 | 313 | // 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
| 314 | 314 | // 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * This just previews the question groups tab that comes in caffeinated. |
|
| 321 | - * |
|
| 322 | - * @return string html |
|
| 323 | - */ |
|
| 324 | - protected function _questions_groups_preview() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
| 327 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 328 | - 'event_espresso') . '" />'; |
|
| 329 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 330 | - 'event_espresso') . '</strong>'; |
|
| 331 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Extracts the question field's values from the POST request to update or insert them |
|
| 337 | - * |
|
| 338 | - * @param \EEM_Base $model |
|
| 339 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
| 340 | - */ |
|
| 341 | - protected function _set_column_values_for(EEM_Base $model) |
|
| 342 | - { |
|
| 343 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 344 | - $set_column_values = array(); |
|
| 345 | - |
|
| 346 | - //some initial checks for proper values. |
|
| 347 | - //if QST_admin_only, then no matter what QST_required is we disable. |
|
| 348 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 349 | - $this->_req_data['QST_required'] = 0; |
|
| 350 | - } |
|
| 351 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
| 352 | - // basically if QSG_identifier is empty or not set |
|
| 353 | - if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
| 354 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
| 355 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * This just previews the question groups tab that comes in caffeinated. |
|
| 321 | + * |
|
| 322 | + * @return string html |
|
| 323 | + */ |
|
| 324 | + protected function _questions_groups_preview() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
| 327 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 328 | + 'event_espresso') . '" />'; |
|
| 329 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 330 | + 'event_espresso') . '</strong>'; |
|
| 331 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Extracts the question field's values from the POST request to update or insert them |
|
| 337 | + * |
|
| 338 | + * @param \EEM_Base $model |
|
| 339 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
| 340 | + */ |
|
| 341 | + protected function _set_column_values_for(EEM_Base $model) |
|
| 342 | + { |
|
| 343 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 344 | + $set_column_values = array(); |
|
| 345 | + |
|
| 346 | + //some initial checks for proper values. |
|
| 347 | + //if QST_admin_only, then no matter what QST_required is we disable. |
|
| 348 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 349 | + $this->_req_data['QST_required'] = 0; |
|
| 350 | + } |
|
| 351 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
| 352 | + // basically if QSG_identifier is empty or not set |
|
| 353 | + if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
| 354 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
| 355 | + $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 356 | 356 | // dd($set_column_values); |
| 357 | - } //if the admin label is blank, use a slug version of the question text |
|
| 358 | - else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
| 359 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
| 360 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
| 361 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 362 | - $set_column_values[$fieldName] = 0; |
|
| 363 | - } else if ($fieldName === 'QST_max') { |
|
| 364 | - $qst_system = EEM_Question::instance()->get_var( |
|
| 365 | - array( |
|
| 366 | - array( |
|
| 367 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
| 368 | - ), |
|
| 369 | - ), |
|
| 370 | - 'QST_system'); |
|
| 371 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 372 | - if (empty($this->_req_data['QST_max']) || |
|
| 373 | - $this->_req_data['QST_max'] > $max_max |
|
| 374 | - ) { |
|
| 375 | - $set_column_values[$fieldName] = $max_max; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
| 381 | - if ( |
|
| 382 | - ! isset($set_column_values[$fieldName]) && |
|
| 383 | - isset($this->_req_data[$fieldName]) |
|
| 384 | - ) { |
|
| 385 | - $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - } |
|
| 389 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - *_questions_overview_list_table |
|
| 395 | - */ |
|
| 396 | - protected function _questions_overview_list_table() |
|
| 397 | - { |
|
| 398 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
| 399 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * _edit_question |
|
| 405 | - */ |
|
| 406 | - protected function _edit_question() |
|
| 407 | - { |
|
| 408 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 409 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
| 410 | - |
|
| 411 | - switch ($this->_req_action) { |
|
| 412 | - case 'add_question' : |
|
| 413 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
| 414 | - break; |
|
| 415 | - case 'edit_question' : |
|
| 416 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
| 417 | - break; |
|
| 418 | - default : |
|
| 419 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // add PRC_ID to title if editing |
|
| 423 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 424 | - if ($ID) { |
|
| 425 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
| 426 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 427 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
| 428 | - } else { |
|
| 429 | - $question = EE_Question::new_instance(); |
|
| 430 | - $question->set_order_to_latest(); |
|
| 431 | - $this->_set_add_edit_form_tags('insert_question'); |
|
| 432 | - } |
|
| 433 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
| 434 | - $this->_template_args['QST_ID'] = $ID; |
|
| 435 | - $this->_template_args['question'] = $question; |
|
| 436 | - $this->_template_args['question_types'] = $question_types; |
|
| 437 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question($question->system_ID()); |
|
| 438 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
| 439 | - $this->_set_publish_post_box_vars('id', $ID); |
|
| 440 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 441 | - $this->_template_args, true); |
|
| 442 | - |
|
| 443 | - // the details template wrapper |
|
| 444 | - $this->display_admin_page_with_sidebar(); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * @return string |
|
| 450 | - */ |
|
| 451 | - protected function _get_question_type_descriptions() |
|
| 452 | - { |
|
| 453 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 454 | - $descriptions = ''; |
|
| 455 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
| 456 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
| 457 | - if ($type == 'HTML_TEXTAREA') { |
|
| 458 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
| 459 | - $question_type_description .= sprintf( |
|
| 460 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
| 461 | - '<br/>', |
|
| 462 | - $html->get_list_of_allowed_tags() |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - $descriptions .= EEH_HTML::p( |
|
| 466 | - $question_type_description, |
|
| 467 | - 'question_type_description-' . $type, |
|
| 468 | - 'question_type_description description', |
|
| 469 | - 'display:none;' |
|
| 470 | - ); |
|
| 471 | - } |
|
| 472 | - return $descriptions; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * @param bool|true $new_question |
|
| 478 | - * @throws \EE_Error |
|
| 479 | - */ |
|
| 480 | - protected function _insert_or_update_question($new_question = true) |
|
| 481 | - { |
|
| 482 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 483 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
| 484 | - if ($new_question) { |
|
| 485 | - $ID = $this->_question_model->insert($set_column_values); |
|
| 486 | - $success = $ID ? true : false; |
|
| 487 | - $action_desc = 'added'; |
|
| 488 | - } else { |
|
| 489 | - $ID = absint($this->_req_data['QST_ID']); |
|
| 490 | - $pk = $this->_question_model->primary_key_name(); |
|
| 491 | - $wheres = array($pk => $ID); |
|
| 492 | - unset($set_column_values[$pk]); |
|
| 493 | - $success = $this->_question_model->update($set_column_values, array($wheres)); |
|
| 494 | - $action_desc = 'updated'; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($ID) { |
|
| 498 | - //save the related options |
|
| 499 | - //trash removed options, save old ones |
|
| 500 | - //get list of all options |
|
| 501 | - /** @type EE_Question $question */ |
|
| 502 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
| 503 | - $options = $question->options(); |
|
| 504 | - if (! empty($options)) { |
|
| 505 | - foreach ($options as $option_ID => $option) { |
|
| 506 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
| 507 | - if ($option_req_index !== false) { |
|
| 508 | - $option->save($this->_req_data['question_options'][$option_req_index]); |
|
| 509 | - } else { |
|
| 510 | - //not found, remove it |
|
| 511 | - $option->delete(); |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - //save new related options |
|
| 516 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
| 517 | - if (empty($option_req_data['QSO_ID']) && ((isset($option_req_data['QSO_value']) && $option_req_data['QSO_value'] !== '') || ! empty($option_req_data['QSO_desc']))) {//no ID! save it! |
|
| 518 | - if (! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') { |
|
| 519 | - $option_req_data['QSO_value'] = $option_req_data['QSO_desc']; |
|
| 520 | - } |
|
| 521 | - $new_option = EE_Question_Option::new_instance(array( |
|
| 522 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
| 523 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
| 524 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
| 525 | - 'QST_ID' => $question->ID(), |
|
| 526 | - )); |
|
| 527 | - $new_option->save(); |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
| 532 | - if ($success !== false) { |
|
| 533 | - $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 534 | - $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
| 535 | - $this->_question_model->item_name()); |
|
| 536 | - EE_Error::add_success($msg); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
| 545 | - * by ID |
|
| 546 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
| 547 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
| 548 | - * |
|
| 549 | - * @param int $ID of the question option to find |
|
| 550 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
| 551 | - */ |
|
| 552 | - protected function _get_option_req_data_index($ID) |
|
| 553 | - { |
|
| 554 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
| 555 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
| 556 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 557 | - return $num; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - return false; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /***********/ |
|
| 567 | - /* QUERIES */ |
|
| 568 | - /** |
|
| 569 | - * For internal use in getting all the query parameters |
|
| 570 | - * (because it's pretty well the same between question, question groups, |
|
| 571 | - * and for both when searching for trashed and untrashed ones) |
|
| 572 | - * |
|
| 573 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
| 574 | - * @param int $per_page |
|
| 575 | - * @param int $current_page |
|
| 576 | - * @return array lik EEM_Base::get_all's $query_params parameter |
|
| 577 | - */ |
|
| 578 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
| 579 | - { |
|
| 580 | - $query_params = array(); |
|
| 581 | - $offset = ($current_page - 1) * $per_page; |
|
| 582 | - $query_params['limit'] = array($offset, $per_page); |
|
| 583 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 584 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
| 585 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
| 586 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
| 587 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
| 588 | - if (! empty($search_string)) { |
|
| 589 | - if ($model instanceof EEM_Question_Group) { |
|
| 590 | - $query_params[0] = array( |
|
| 591 | - 'OR' => array( |
|
| 592 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
| 593 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
| 594 | - ), |
|
| 595 | - ); |
|
| 596 | - } else { |
|
| 597 | - $query_params[0] = array( |
|
| 598 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
| 604 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
| 357 | + } //if the admin label is blank, use a slug version of the question text |
|
| 358 | + else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
| 359 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
| 360 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
| 361 | + } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 362 | + $set_column_values[$fieldName] = 0; |
|
| 363 | + } else if ($fieldName === 'QST_max') { |
|
| 364 | + $qst_system = EEM_Question::instance()->get_var( |
|
| 365 | + array( |
|
| 366 | + array( |
|
| 367 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
| 368 | + ), |
|
| 369 | + ), |
|
| 370 | + 'QST_system'); |
|
| 371 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 372 | + if (empty($this->_req_data['QST_max']) || |
|
| 373 | + $this->_req_data['QST_max'] > $max_max |
|
| 374 | + ) { |
|
| 375 | + $set_column_values[$fieldName] = $max_max; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
| 381 | + if ( |
|
| 382 | + ! isset($set_column_values[$fieldName]) && |
|
| 383 | + isset($this->_req_data[$fieldName]) |
|
| 384 | + ) { |
|
| 385 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + } |
|
| 389 | + return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + *_questions_overview_list_table |
|
| 395 | + */ |
|
| 396 | + protected function _questions_overview_list_table() |
|
| 397 | + { |
|
| 398 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
| 399 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * _edit_question |
|
| 405 | + */ |
|
| 406 | + protected function _edit_question() |
|
| 407 | + { |
|
| 408 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 409 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
| 410 | + |
|
| 411 | + switch ($this->_req_action) { |
|
| 412 | + case 'add_question' : |
|
| 413 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
| 414 | + break; |
|
| 415 | + case 'edit_question' : |
|
| 416 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
| 417 | + break; |
|
| 418 | + default : |
|
| 419 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // add PRC_ID to title if editing |
|
| 423 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 424 | + if ($ID) { |
|
| 425 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
| 426 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 427 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
| 428 | + } else { |
|
| 429 | + $question = EE_Question::new_instance(); |
|
| 430 | + $question->set_order_to_latest(); |
|
| 431 | + $this->_set_add_edit_form_tags('insert_question'); |
|
| 432 | + } |
|
| 433 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
| 434 | + $this->_template_args['QST_ID'] = $ID; |
|
| 435 | + $this->_template_args['question'] = $question; |
|
| 436 | + $this->_template_args['question_types'] = $question_types; |
|
| 437 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question($question->system_ID()); |
|
| 438 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
| 439 | + $this->_set_publish_post_box_vars('id', $ID); |
|
| 440 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 441 | + $this->_template_args, true); |
|
| 442 | + |
|
| 443 | + // the details template wrapper |
|
| 444 | + $this->display_admin_page_with_sidebar(); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * @return string |
|
| 450 | + */ |
|
| 451 | + protected function _get_question_type_descriptions() |
|
| 452 | + { |
|
| 453 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 454 | + $descriptions = ''; |
|
| 455 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
| 456 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
| 457 | + if ($type == 'HTML_TEXTAREA') { |
|
| 458 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
| 459 | + $question_type_description .= sprintf( |
|
| 460 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
| 461 | + '<br/>', |
|
| 462 | + $html->get_list_of_allowed_tags() |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + $descriptions .= EEH_HTML::p( |
|
| 466 | + $question_type_description, |
|
| 467 | + 'question_type_description-' . $type, |
|
| 468 | + 'question_type_description description', |
|
| 469 | + 'display:none;' |
|
| 470 | + ); |
|
| 471 | + } |
|
| 472 | + return $descriptions; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * @param bool|true $new_question |
|
| 478 | + * @throws \EE_Error |
|
| 479 | + */ |
|
| 480 | + protected function _insert_or_update_question($new_question = true) |
|
| 481 | + { |
|
| 482 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 483 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
| 484 | + if ($new_question) { |
|
| 485 | + $ID = $this->_question_model->insert($set_column_values); |
|
| 486 | + $success = $ID ? true : false; |
|
| 487 | + $action_desc = 'added'; |
|
| 488 | + } else { |
|
| 489 | + $ID = absint($this->_req_data['QST_ID']); |
|
| 490 | + $pk = $this->_question_model->primary_key_name(); |
|
| 491 | + $wheres = array($pk => $ID); |
|
| 492 | + unset($set_column_values[$pk]); |
|
| 493 | + $success = $this->_question_model->update($set_column_values, array($wheres)); |
|
| 494 | + $action_desc = 'updated'; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($ID) { |
|
| 498 | + //save the related options |
|
| 499 | + //trash removed options, save old ones |
|
| 500 | + //get list of all options |
|
| 501 | + /** @type EE_Question $question */ |
|
| 502 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
| 503 | + $options = $question->options(); |
|
| 504 | + if (! empty($options)) { |
|
| 505 | + foreach ($options as $option_ID => $option) { |
|
| 506 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
| 507 | + if ($option_req_index !== false) { |
|
| 508 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
| 509 | + } else { |
|
| 510 | + //not found, remove it |
|
| 511 | + $option->delete(); |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + //save new related options |
|
| 516 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
| 517 | + if (empty($option_req_data['QSO_ID']) && ((isset($option_req_data['QSO_value']) && $option_req_data['QSO_value'] !== '') || ! empty($option_req_data['QSO_desc']))) {//no ID! save it! |
|
| 518 | + if (! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') { |
|
| 519 | + $option_req_data['QSO_value'] = $option_req_data['QSO_desc']; |
|
| 520 | + } |
|
| 521 | + $new_option = EE_Question_Option::new_instance(array( |
|
| 522 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
| 523 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
| 524 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
| 525 | + 'QST_ID' => $question->ID(), |
|
| 526 | + )); |
|
| 527 | + $new_option->save(); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
| 532 | + if ($success !== false) { |
|
| 533 | + $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 534 | + $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
| 535 | + $this->_question_model->item_name()); |
|
| 536 | + EE_Error::add_success($msg); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
| 545 | + * by ID |
|
| 546 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
| 547 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
| 548 | + * |
|
| 549 | + * @param int $ID of the question option to find |
|
| 550 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
| 551 | + */ |
|
| 552 | + protected function _get_option_req_data_index($ID) |
|
| 553 | + { |
|
| 554 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
| 555 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
| 556 | + if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 557 | + return $num; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + return false; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /***********/ |
|
| 567 | + /* QUERIES */ |
|
| 568 | + /** |
|
| 569 | + * For internal use in getting all the query parameters |
|
| 570 | + * (because it's pretty well the same between question, question groups, |
|
| 571 | + * and for both when searching for trashed and untrashed ones) |
|
| 572 | + * |
|
| 573 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
| 574 | + * @param int $per_page |
|
| 575 | + * @param int $current_page |
|
| 576 | + * @return array lik EEM_Base::get_all's $query_params parameter |
|
| 577 | + */ |
|
| 578 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
| 579 | + { |
|
| 580 | + $query_params = array(); |
|
| 581 | + $offset = ($current_page - 1) * $per_page; |
|
| 582 | + $query_params['limit'] = array($offset, $per_page); |
|
| 583 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 584 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
| 585 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
| 586 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
| 587 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
| 588 | + if (! empty($search_string)) { |
|
| 589 | + if ($model instanceof EEM_Question_Group) { |
|
| 590 | + $query_params[0] = array( |
|
| 591 | + 'OR' => array( |
|
| 592 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
| 593 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
| 594 | + ), |
|
| 595 | + ); |
|
| 596 | + } else { |
|
| 597 | + $query_params[0] = array( |
|
| 598 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
| 604 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
| 605 | 605 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
| 606 | 606 | $query_params[0] = array( |
| 607 | 607 | 'AND' => array( |
@@ -631,62 +631,62 @@ discard block |
||
| 631 | 631 | } |
| 632 | 632 | }/**/ |
| 633 | 633 | |
| 634 | - return $query_params; |
|
| 635 | - |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * @param int $per_page |
|
| 641 | - * @param int $current_page |
|
| 642 | - * @param bool|false $count |
|
| 643 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 644 | - */ |
|
| 645 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
| 646 | - { |
|
| 647 | - $QST = EEM_Question::instance(); |
|
| 648 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
| 649 | - if ($count) { |
|
| 650 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 651 | - $results = $QST->count($where); |
|
| 652 | - } else { |
|
| 653 | - $results = $QST->get_all($query_params); |
|
| 654 | - } |
|
| 655 | - return $results; |
|
| 656 | - |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * @param $per_page |
|
| 662 | - * @param int $current_page |
|
| 663 | - * @param bool|false $count |
|
| 664 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 665 | - */ |
|
| 666 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 667 | - { |
|
| 668 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 669 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 670 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 671 | - return $questions; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * @param $per_page |
|
| 677 | - * @param int $current_page |
|
| 678 | - * @param bool|false $count |
|
| 679 | - * @return \EE_Soft_Delete_Base_Class[] |
|
| 680 | - */ |
|
| 681 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 682 | - { |
|
| 683 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
| 684 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 685 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 686 | - return $questionGroupModel->get_all( |
|
| 687 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 634 | + return $query_params; |
|
| 635 | + |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * @param int $per_page |
|
| 641 | + * @param int $current_page |
|
| 642 | + * @param bool|false $count |
|
| 643 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 644 | + */ |
|
| 645 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
| 646 | + { |
|
| 647 | + $QST = EEM_Question::instance(); |
|
| 648 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
| 649 | + if ($count) { |
|
| 650 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 651 | + $results = $QST->count($where); |
|
| 652 | + } else { |
|
| 653 | + $results = $QST->get_all($query_params); |
|
| 654 | + } |
|
| 655 | + return $results; |
|
| 656 | + |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * @param $per_page |
|
| 662 | + * @param int $current_page |
|
| 663 | + * @param bool|false $count |
|
| 664 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 665 | + */ |
|
| 666 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 667 | + { |
|
| 668 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 669 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 670 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 671 | + return $questions; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * @param $per_page |
|
| 677 | + * @param int $current_page |
|
| 678 | + * @param bool|false $count |
|
| 679 | + * @return \EE_Soft_Delete_Base_Class[] |
|
| 680 | + */ |
|
| 681 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 682 | + { |
|
| 683 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
| 684 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 685 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 686 | + return $questionGroupModel->get_all( |
|
| 687 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | 691 | |
| 692 | 692 | } //ends Registration_Form_Admin_Page class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function __construct($routing = true) |
| 68 | 68 | { |
| 69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 69 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
| 70 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
| 71 | 71 | $this->_question_model = EEM_Question::instance(); |
| 72 | 72 | $this->_question_group_model = EEM_Question_Group::instance(); |
| 73 | 73 | parent::__construct($routing); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | public function load_scripts_styles() |
| 233 | 233 | { |
| 234 | 234 | wp_register_style('espresso_registration', |
| 235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 235 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | 236 | wp_enqueue_style('espresso_registration'); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | { |
| 259 | 259 | $this->load_scripts_styles_forms(); |
| 260 | 260 | wp_register_script('espresso_registration_form_single', |
| 261 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 261 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 262 | 262 | EVENT_ESPRESSO_VERSION, true); |
| 263 | 263 | wp_enqueue_script('espresso_registration_form_single'); |
| 264 | 264 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | { |
| 268 | 268 | $this->load_scripts_styles_forms(); |
| 269 | 269 | wp_register_script('espresso_registration_form_single', |
| 270 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 270 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 271 | 271 | EVENT_ESPRESSO_VERSION, true); |
| 272 | 272 | wp_enqueue_script('espresso_registration_form_single'); |
| 273 | 273 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | public function recaptcha_info_help_tab() |
| 277 | 277 | { |
| 278 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 278 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
| 279 | 279 | EEH_Template::display_template($template, array()); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | protected function _questions_groups_preview() |
| 325 | 325 | { |
| 326 | 326 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
| 327 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 328 | - 'event_espresso') . '" />'; |
|
| 329 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 330 | - 'event_espresso') . '</strong>'; |
|
| 327 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 328 | + 'event_espresso').'" />'; |
|
| 329 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 330 | + 'event_espresso').'</strong>'; |
|
| 331 | 331 | $this->display_admin_caf_preview_page('question_groups_tab'); |
| 332 | 332 | } |
| 333 | 333 | |
@@ -345,20 +345,20 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | //some initial checks for proper values. |
| 347 | 347 | //if QST_admin_only, then no matter what QST_required is we disable. |
| 348 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 348 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
| 349 | 349 | $this->_req_data['QST_required'] = 0; |
| 350 | 350 | } |
| 351 | 351 | foreach ($model->field_settings() as $fieldName => $settings) { |
| 352 | 352 | // basically if QSG_identifier is empty or not set |
| 353 | 353 | if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
| 354 | 354 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
| 355 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 355 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
| 356 | 356 | // dd($set_column_values); |
| 357 | 357 | } //if the admin label is blank, use a slug version of the question text |
| 358 | 358 | else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
| 359 | 359 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
| 360 | 360 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
| 361 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 361 | + } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
| 362 | 362 | $set_column_values[$fieldName] = 0; |
| 363 | 363 | } else if ($fieldName === 'QST_max') { |
| 364 | 364 | $qst_system = EEM_Question::instance()->get_var( |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | ), |
| 369 | 369 | ), |
| 370 | 370 | 'QST_system'); |
| 371 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 371 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 372 | 372 | if (empty($this->_req_data['QST_max']) || |
| 373 | 373 | $this->_req_data['QST_max'] > $max_max |
| 374 | 374 | ) { |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | } |
| 389 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 389 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // add PRC_ID to title if editing |
| 423 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 423 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 424 | 424 | if ($ID) { |
| 425 | 425 | $question = $this->_question_model->get_one_by_ID($ID); |
| 426 | 426 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question($question->system_ID()); |
| 438 | 438 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
| 439 | 439 | $this->_set_publish_post_box_vars('id', $ID); |
| 440 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 440 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
| 441 | 441 | $this->_template_args, true); |
| 442 | 442 | |
| 443 | 443 | // the details template wrapper |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | $descriptions .= EEH_HTML::p( |
| 466 | 466 | $question_type_description, |
| 467 | - 'question_type_description-' . $type, |
|
| 467 | + 'question_type_description-'.$type, |
|
| 468 | 468 | 'question_type_description description', |
| 469 | 469 | 'display:none;' |
| 470 | 470 | ); |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | /** @type EE_Question $question */ |
| 502 | 502 | $question = $this->_question_model->get_one_by_ID($ID); |
| 503 | 503 | $options = $question->options(); |
| 504 | - if (! empty($options)) { |
|
| 504 | + if ( ! empty($options)) { |
|
| 505 | 505 | foreach ($options as $option_ID => $option) { |
| 506 | 506 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
| 507 | 507 | if ($option_req_index !== false) { |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | //save new related options |
| 516 | 516 | foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
| 517 | 517 | if (empty($option_req_data['QSO_ID']) && ((isset($option_req_data['QSO_value']) && $option_req_data['QSO_value'] !== '') || ! empty($option_req_data['QSO_desc']))) {//no ID! save it! |
| 518 | - if (! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') { |
|
| 518 | + if ( ! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') { |
|
| 519 | 519 | $option_req_data['QSO_value'] = $option_req_data['QSO_desc']; |
| 520 | 520 | } |
| 521 | 521 | $new_option = EE_Question_Option::new_instance(array( |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | { |
| 554 | 554 | $req_data_for_question_options = $this->_req_data['question_options']; |
| 555 | 555 | foreach ($req_data_for_question_options as $num => $option_data) { |
| 556 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 556 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
| 557 | 557 | return $num; |
| 558 | 558 | } |
| 559 | 559 | } |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
| 586 | 586 | $query_params['order_by'] = array($field_to_order_by => $order); |
| 587 | 587 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
| 588 | - if (! empty($search_string)) { |
|
| 588 | + if ( ! empty($search_string)) { |
|
| 589 | 589 | if ($model instanceof EEM_Question_Group) { |
| 590 | 590 | $query_params[0] = array( |
| 591 | 591 | 'OR' => array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('NO direct script access allowed'); |
|
| 2 | + exit('NO direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -17,2213 +17,2213 @@ discard block |
||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | - */ |
|
| 23 | - protected $_message_resource_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type string $_active_message_type_name |
|
| 27 | - */ |
|
| 28 | - protected $_active_message_type_name = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type EE_messenger $_active_messenger |
|
| 32 | - */ |
|
| 33 | - protected $_active_messenger; |
|
| 34 | - protected $_activate_state; |
|
| 35 | - protected $_activate_meta_box_type; |
|
| 36 | - protected $_current_message_meta_box; |
|
| 37 | - protected $_current_message_meta_box_object; |
|
| 38 | - protected $_context_switcher; |
|
| 39 | - protected $_shortcodes = array(); |
|
| 40 | - protected $_active_messengers = array(); |
|
| 41 | - protected $_active_message_types = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | - */ |
|
| 46 | - protected $_message_template_group; |
|
| 47 | - protected $_m_mt_settings = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | - * |
|
| 54 | - * @since 4.5.0 |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack |
|
| 57 | - */ |
|
| 58 | - protected $_template_pack; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | - * group is. If there is no group then it automatically gets set to default. |
|
| 64 | - * |
|
| 65 | - * @since 4.5.0 |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $_variation; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $routing |
|
| 74 | - */ |
|
| 75 | - public function __construct($routing = true) |
|
| 76 | - { |
|
| 77 | - //make sure messages autoloader is running |
|
| 78 | - EED_Messages::set_autoloaders(); |
|
| 79 | - parent::__construct($routing); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - protected function _init_page_props() |
|
| 84 | - { |
|
| 85 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | - $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | - |
|
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | - |
|
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | - $this->_load_message_resource_manager(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _load_message_resource_manager() |
|
| 104 | - { |
|
| 105 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated 4.9.9.rc.014 |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_messengers_for_list_table() |
|
| 114 | - { |
|
| 115 | - EE_Error::doing_it_wrong( |
|
| 116 | - __METHOD__, |
|
| 117 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 20 | + /** |
|
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | + */ |
|
| 23 | + protected $_message_resource_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type string $_active_message_type_name |
|
| 27 | + */ |
|
| 28 | + protected $_active_message_type_name = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type EE_messenger $_active_messenger |
|
| 32 | + */ |
|
| 33 | + protected $_active_messenger; |
|
| 34 | + protected $_activate_state; |
|
| 35 | + protected $_activate_meta_box_type; |
|
| 36 | + protected $_current_message_meta_box; |
|
| 37 | + protected $_current_message_meta_box_object; |
|
| 38 | + protected $_context_switcher; |
|
| 39 | + protected $_shortcodes = array(); |
|
| 40 | + protected $_active_messengers = array(); |
|
| 41 | + protected $_active_message_types = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | + */ |
|
| 46 | + protected $_message_template_group; |
|
| 47 | + protected $_m_mt_settings = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | + * |
|
| 54 | + * @since 4.5.0 |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack |
|
| 57 | + */ |
|
| 58 | + protected $_template_pack; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | + * group is. If there is no group then it automatically gets set to default. |
|
| 64 | + * |
|
| 65 | + * @since 4.5.0 |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $_variation; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $routing |
|
| 74 | + */ |
|
| 75 | + public function __construct($routing = true) |
|
| 76 | + { |
|
| 77 | + //make sure messages autoloader is running |
|
| 78 | + EED_Messages::set_autoloaders(); |
|
| 79 | + parent::__construct($routing); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + protected function _init_page_props() |
|
| 84 | + { |
|
| 85 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | + $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | + |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | + |
|
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | + $this->_load_message_resource_manager(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _load_message_resource_manager() |
|
| 104 | + { |
|
| 105 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated 4.9.9.rc.014 |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_messengers_for_list_table() |
|
| 114 | + { |
|
| 115 | + EE_Error::doing_it_wrong( |
|
| 116 | + __METHOD__, |
|
| 117 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via |
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'), |
| 120 | - '4.9.9.rc.014' |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $m_values = array(); |
|
| 124 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | - //setup messengers for selects |
|
| 126 | - $i = 1; |
|
| 127 | - foreach ($active_messengers as $active_messenger) { |
|
| 128 | - if ($active_messenger instanceof EE_Message) { |
|
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $m_values; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @deprecated 4.9.9.rc.014 |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function get_message_types_for_list_table() |
|
| 144 | - { |
|
| 145 | - EE_Error::doing_it_wrong( |
|
| 146 | - __METHOD__, |
|
| 147 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 120 | + '4.9.9.rc.014' |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $m_values = array(); |
|
| 124 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | + //setup messengers for selects |
|
| 126 | + $i = 1; |
|
| 127 | + foreach ($active_messengers as $active_messenger) { |
|
| 128 | + if ($active_messenger instanceof EE_Message) { |
|
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $m_values; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @deprecated 4.9.9.rc.014 |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function get_message_types_for_list_table() |
|
| 144 | + { |
|
| 145 | + EE_Error::doing_it_wrong( |
|
| 146 | + __METHOD__, |
|
| 147 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via |
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'), |
| 150 | - '4.9.9.rc.014' |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $mt_values = array(); |
|
| 154 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | - $i = 1; |
|
| 156 | - foreach ($active_messages as $active_message) { |
|
| 157 | - if ($active_message instanceof EE_Message) { |
|
| 158 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | - $i++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $mt_values; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @deprecated 4.9.9.rc.014 |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function get_contexts_for_message_types_for_list_table() |
|
| 173 | - { |
|
| 174 | - EE_Error::doing_it_wrong( |
|
| 175 | - __METHOD__, |
|
| 176 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 150 | + '4.9.9.rc.014' |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $mt_values = array(); |
|
| 154 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | + $i = 1; |
|
| 156 | + foreach ($active_messages as $active_message) { |
|
| 157 | + if ($active_message instanceof EE_Message) { |
|
| 158 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | + $i++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $mt_values; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @deprecated 4.9.9.rc.014 |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function get_contexts_for_message_types_for_list_table() |
|
| 173 | + { |
|
| 174 | + EE_Error::doing_it_wrong( |
|
| 175 | + __METHOD__, |
|
| 176 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via |
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'), |
| 179 | - '4.9.9.rc.014' |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $contexts = array(); |
|
| 183 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | - foreach ($active_message_contexts as $active_message) { |
|
| 185 | - if ($active_message instanceof EE_Message) { |
|
| 186 | - $message_type = $active_message->message_type_object(); |
|
| 187 | - if ($message_type instanceof EE_message_type) { |
|
| 188 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | - $contexts[$context] = $context_details['label']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $contexts; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generate select input with provided messenger options array. |
|
| 202 | - * |
|
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | - * labels. |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function get_messengers_select_input($messenger_options) |
|
| 209 | - { |
|
| 210 | - //if empty or just one value then just return an empty string |
|
| 211 | - if (empty($messenger_options) |
|
| 212 | - || ! is_array($messenger_options) |
|
| 213 | - || count($messenger_options) === 1 |
|
| 214 | - ) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - //merge in default |
|
| 218 | - $messenger_options = array_merge( |
|
| 219 | - array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | - $messenger_options |
|
| 221 | - ); |
|
| 222 | - $input = new EE_Select_Input( |
|
| 223 | - $messenger_options, |
|
| 224 | - array( |
|
| 225 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | - 'html_class' => 'wide', |
|
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | - : 'none_selected' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - return $input->get_html_for_input(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Generate select input with provided message type options array. |
|
| 240 | - * |
|
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | - * message type labels |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_message_types_select_input($message_type_options) |
|
| 247 | - { |
|
| 248 | - //if empty or count of options is 1 then just return an empty string |
|
| 249 | - if (empty($message_type_options) |
|
| 250 | - || ! is_array($message_type_options) |
|
| 251 | - || count($message_type_options) === 1 |
|
| 252 | - ) { |
|
| 253 | - return ''; |
|
| 254 | - } |
|
| 255 | - //merge in default |
|
| 256 | - $message_type_options = array_merge( |
|
| 257 | - array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | - $message_type_options |
|
| 259 | - ); |
|
| 260 | - $input = new EE_Select_Input( |
|
| 261 | - $message_type_options, |
|
| 262 | - array( |
|
| 263 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | - 'html_class' => 'wide', |
|
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | - : 'none_selected', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return $input->get_html_for_input(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generate select input with provide message type contexts array. |
|
| 278 | - * |
|
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | - * context label. |
|
| 281 | - * |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | - { |
|
| 286 | - //if empty or count of options is one then just return empty string |
|
| 287 | - if (empty($context_options) |
|
| 288 | - || ! is_array($context_options) |
|
| 289 | - || count($context_options) === 1 |
|
| 290 | - ) { |
|
| 291 | - return ''; |
|
| 292 | - } |
|
| 293 | - //merge in default |
|
| 294 | - $context_options = array_merge( |
|
| 295 | - array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | - $context_options |
|
| 297 | - ); |
|
| 298 | - $input = new EE_Select_Input( |
|
| 299 | - $context_options, |
|
| 300 | - array( |
|
| 301 | - 'html_name' => 'ee_context_filter_by', |
|
| 302 | - 'html_id' => 'ee_context_filter_by', |
|
| 303 | - 'html_class' => 'wide', |
|
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | - : 'none_selected', |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - return $input->get_html_for_input(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _ajax_hooks() |
|
| 315 | - { |
|
| 316 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - protected function _define_page_props() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = $this->page_label; |
|
| 327 | - $this->_labels = array( |
|
| 328 | - 'buttons' => array( |
|
| 329 | - 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | - 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | - 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | - ), |
|
| 333 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | - * @access protected |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function _set_page_routes() |
|
| 344 | - { |
|
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | - ? $this->_req_data['GRP_ID'] |
|
| 347 | - : 0; |
|
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | - ? $this->_req_data['id'] |
|
| 350 | - : $grp_id; |
|
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | - ? $this->_req_data['MSG_ID'] |
|
| 353 | - : 0; |
|
| 354 | - |
|
| 355 | - $this->_page_routes = array( |
|
| 356 | - 'default' => array( |
|
| 357 | - 'func' => '_message_queue_list_table', |
|
| 358 | - 'capability' => 'ee_read_global_messages' |
|
| 359 | - ), |
|
| 360 | - 'global_mtps' => array( |
|
| 361 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | - 'capability' => 'ee_read_global_messages' |
|
| 363 | - ), |
|
| 364 | - 'custom_mtps' => array( |
|
| 365 | - 'func' => '_custom_mtps_preview', |
|
| 366 | - 'capability' => 'ee_read_messages' |
|
| 367 | - ), |
|
| 368 | - 'add_new_message_template' => array( |
|
| 369 | - 'func' => '_add_message_template', |
|
| 370 | - 'capability' => 'ee_edit_messages', |
|
| 371 | - 'noheader' => true |
|
| 372 | - ), |
|
| 373 | - 'edit_message_template' => array( |
|
| 374 | - 'func' => '_edit_message_template', |
|
| 375 | - 'capability' => 'ee_edit_message', |
|
| 376 | - 'obj_id' => $grp_id |
|
| 377 | - ), |
|
| 378 | - 'preview_message' => array( |
|
| 379 | - 'func' => '_preview_message', |
|
| 380 | - 'capability' => 'ee_read_message', |
|
| 381 | - 'obj_id' => $grp_id, |
|
| 382 | - 'noheader' => true, |
|
| 383 | - 'headers_sent_route' => 'display_preview_message' |
|
| 384 | - ), |
|
| 385 | - 'display_preview_message' => array( |
|
| 386 | - 'func' => '_display_preview_message', |
|
| 387 | - 'capability' => 'ee_read_message', |
|
| 388 | - 'obj_id' => $grp_id |
|
| 389 | - ), |
|
| 390 | - 'insert_message_template' => array( |
|
| 391 | - 'func' => '_insert_or_update_message_template', |
|
| 392 | - 'capability' => 'ee_edit_messages', |
|
| 393 | - 'args' => array('new_template' => true), |
|
| 394 | - 'noheader' => true |
|
| 395 | - ), |
|
| 396 | - 'update_message_template' => array( |
|
| 397 | - 'func' => '_insert_or_update_message_template', |
|
| 398 | - 'capability' => 'ee_edit_message', |
|
| 399 | - 'obj_id' => $grp_id, |
|
| 400 | - 'args' => array('new_template' => false), |
|
| 401 | - 'noheader' => true |
|
| 402 | - ), |
|
| 403 | - 'trash_message_template' => array( |
|
| 404 | - 'func' => '_trash_or_restore_message_template', |
|
| 405 | - 'capability' => 'ee_delete_message', |
|
| 406 | - 'obj_id' => $grp_id, |
|
| 407 | - 'args' => array('trash' => true, 'all' => true), |
|
| 408 | - 'noheader' => true |
|
| 409 | - ), |
|
| 410 | - 'trash_message_template_context' => array( |
|
| 411 | - 'func' => '_trash_or_restore_message_template', |
|
| 412 | - 'capability' => 'ee_delete_message', |
|
| 413 | - 'obj_id' => $grp_id, |
|
| 414 | - 'args' => array('trash' => true), |
|
| 415 | - 'noheader' => true |
|
| 416 | - ), |
|
| 417 | - 'restore_message_template' => array( |
|
| 418 | - 'func' => '_trash_or_restore_message_template', |
|
| 419 | - 'capability' => 'ee_delete_message', |
|
| 420 | - 'obj_id' => $grp_id, |
|
| 421 | - 'args' => array('trash' => false, 'all' => true), |
|
| 422 | - 'noheader' => true |
|
| 423 | - ), |
|
| 424 | - 'restore_message_template_context' => array( |
|
| 425 | - 'func' => '_trash_or_restore_message_template', |
|
| 426 | - 'capability' => 'ee_delete_message', |
|
| 427 | - 'obj_id' => $grp_id, |
|
| 428 | - 'args' => array('trash' => false), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'delete_message_template' => array( |
|
| 432 | - 'func' => '_delete_message_template', |
|
| 433 | - 'capability' => 'ee_delete_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'reset_to_default' => array( |
|
| 438 | - 'func' => '_reset_to_default_template', |
|
| 439 | - 'capability' => 'ee_edit_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'noheader' => true |
|
| 442 | - ), |
|
| 443 | - 'settings' => array( |
|
| 444 | - 'func' => '_settings', |
|
| 445 | - 'capability' => 'manage_options' |
|
| 446 | - ), |
|
| 447 | - 'update_global_settings' => array( |
|
| 448 | - 'func' => '_update_global_settings', |
|
| 449 | - 'capability' => 'manage_options', |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'generate_now' => array( |
|
| 453 | - 'func' => '_generate_now', |
|
| 454 | - 'capability' => 'ee_send_message', |
|
| 455 | - 'noheader' => true |
|
| 456 | - ), |
|
| 457 | - 'generate_and_send_now' => array( |
|
| 458 | - 'func' => '_generate_and_send_now', |
|
| 459 | - 'capability' => 'ee_send_message', |
|
| 460 | - 'noheader' => true |
|
| 461 | - ), |
|
| 462 | - 'queue_for_resending' => array( |
|
| 463 | - 'func' => '_queue_for_resending', |
|
| 464 | - 'capability' => 'ee_send_message', |
|
| 465 | - 'noheader' => true |
|
| 466 | - ), |
|
| 467 | - 'send_now' => array( |
|
| 468 | - 'func' => '_send_now', |
|
| 469 | - 'capability' => 'ee_send_message', |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'delete_ee_message' => array( |
|
| 473 | - 'func' => '_delete_ee_messages', |
|
| 474 | - 'capability' => 'ee_delete_message', |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'delete_ee_messages' => array( |
|
| 478 | - 'func' => '_delete_ee_messages', |
|
| 479 | - 'capability' => 'ee_delete_messages', |
|
| 480 | - 'noheader' => true, |
|
| 481 | - 'obj_id' => $msg_id |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - protected function _set_page_config() |
|
| 488 | - { |
|
| 489 | - $this->_page_config = array( |
|
| 490 | - 'default' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | - 'order' => 10 |
|
| 494 | - ), |
|
| 495 | - 'list_table' => 'EE_Message_List_Table', |
|
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | - 'require_nonce' => false |
|
| 498 | - ), |
|
| 499 | - 'global_mtps' => array( |
|
| 500 | - 'nav' => array( |
|
| 501 | - 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | - 'order' => 20 |
|
| 503 | - ), |
|
| 504 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | - 'help_tabs' => array( |
|
| 506 | - 'messages_overview_help_tab' => array( |
|
| 507 | - 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | - 'filename' => 'messages_overview' |
|
| 509 | - ), |
|
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | - 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | - ), |
|
| 514 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | - 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | - 'filename' => 'messages_overview_filters' |
|
| 517 | - ), |
|
| 518 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | - 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | - 'filename' => 'messages_overview_views' |
|
| 521 | - ), |
|
| 522 | - 'message_overview_message_types_help_tab' => array( |
|
| 523 | - 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | - 'filename' => 'messages_overview_types' |
|
| 525 | - ), |
|
| 526 | - 'messages_overview_messengers_help_tab' => array( |
|
| 527 | - 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | - 'filename' => 'messages_overview_messengers', |
|
| 529 | - ), |
|
| 530 | - 'messages_overview_other_help_tab' => array( |
|
| 531 | - 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | - 'filename' => 'messages_overview_other', |
|
| 533 | - ), |
|
| 534 | - ), |
|
| 535 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | - 'require_nonce' => false |
|
| 537 | - ), |
|
| 538 | - 'custom_mtps' => array( |
|
| 539 | - 'nav' => array( |
|
| 540 | - 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | - 'order' => 30 |
|
| 542 | - ), |
|
| 543 | - 'help_tabs' => array(), |
|
| 544 | - 'help_tour' => array(), |
|
| 545 | - 'require_nonce' => false |
|
| 546 | - ), |
|
| 547 | - 'add_new_message_template' => array( |
|
| 548 | - 'nav' => array( |
|
| 549 | - 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | - 'order' => 5, |
|
| 551 | - 'persistent' => false |
|
| 552 | - ), |
|
| 553 | - 'require_nonce' => false |
|
| 554 | - ), |
|
| 555 | - 'edit_message_template' => array( |
|
| 556 | - 'labels' => array( |
|
| 557 | - 'buttons' => array( |
|
| 558 | - 'reset' => __('Reset Templates'), |
|
| 559 | - ), |
|
| 560 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | - ), |
|
| 562 | - 'nav' => array( |
|
| 563 | - 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | - 'order' => 5, |
|
| 565 | - 'persistent' => false, |
|
| 566 | - 'url' => '' |
|
| 567 | - ), |
|
| 568 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | - 'has_metaboxes' => true, |
|
| 570 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | - 'help_tabs' => array( |
|
| 572 | - 'edit_message_template' => array( |
|
| 573 | - 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | - 'callback' => 'edit_message_template_help_tab' |
|
| 575 | - ), |
|
| 576 | - 'message_templates_help_tab' => array( |
|
| 577 | - 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | - 'filename' => 'messages_templates' |
|
| 579 | - ), |
|
| 580 | - 'message_template_shortcodes' => array( |
|
| 581 | - 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | - ), |
|
| 584 | - 'message_preview_help_tab' => array( |
|
| 585 | - 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | - 'filename' => 'messages_preview' |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - 'require_nonce' => false |
|
| 590 | - ), |
|
| 591 | - 'display_preview_message' => array( |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'url' => '', |
|
| 596 | - 'persistent' => false |
|
| 597 | - ), |
|
| 598 | - 'help_tabs' => array( |
|
| 599 | - 'preview_message' => array( |
|
| 600 | - 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | - 'callback' => 'preview_message_help_tab' |
|
| 602 | - ) |
|
| 603 | - ), |
|
| 604 | - 'require_nonce' => false |
|
| 605 | - ), |
|
| 606 | - 'settings' => array( |
|
| 607 | - 'nav' => array( |
|
| 608 | - 'label' => __('Settings', 'event_espresso'), |
|
| 609 | - 'order' => 40 |
|
| 610 | - ), |
|
| 611 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | - 'help_tabs' => array( |
|
| 613 | - 'messages_settings_help_tab' => array( |
|
| 614 | - 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | - 'filename' => 'messages_settings' |
|
| 616 | - ), |
|
| 617 | - 'messages_settings_message_types_help_tab' => array( |
|
| 618 | - 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | - 'filename' => 'messages_settings_message_types' |
|
| 620 | - ), |
|
| 621 | - 'messages_settings_messengers_help_tab' => array( |
|
| 622 | - 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | - 'filename' => 'messages_settings_messengers' |
|
| 624 | - ), |
|
| 625 | - ), |
|
| 626 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | - 'require_nonce' => false |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_screen_options() |
|
| 634 | - { |
|
| 635 | - //todo |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - protected function _add_screen_options_global_mtps() |
|
| 640 | - { |
|
| 641 | - /** |
|
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | - */ |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - protected function _add_screen_options_default() |
|
| 653 | - { |
|
| 654 | - $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | - $this->_per_page_screen_option(); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - //none of the below group are currently used for Messages |
|
| 660 | - protected function _add_feature_pointers() |
|
| 661 | - { |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - public function admin_init() |
|
| 665 | - { |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - public function admin_notices() |
|
| 669 | - { |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - public function admin_footer_scripts() |
|
| 673 | - { |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - public function messages_help_tab() |
|
| 678 | - { |
|
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - public function messengers_help_tab() |
|
| 684 | - { |
|
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function message_types_help_tab() |
|
| 690 | - { |
|
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - public function messages_overview_help_tab() |
|
| 696 | - { |
|
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - public function message_templates_help_tab() |
|
| 702 | - { |
|
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - public function edit_message_template_help_tab() |
|
| 708 | - { |
|
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | - $args); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - public function message_template_shortcodes_help_tab() |
|
| 725 | - { |
|
| 726 | - $this->_set_shortcodes(); |
|
| 727 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | - $args); |
|
| 730 | - } |
|
| 179 | + '4.9.9.rc.014' |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $contexts = array(); |
|
| 183 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | + foreach ($active_message_contexts as $active_message) { |
|
| 185 | + if ($active_message instanceof EE_Message) { |
|
| 186 | + $message_type = $active_message->message_type_object(); |
|
| 187 | + if ($message_type instanceof EE_message_type) { |
|
| 188 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | + $contexts[$context] = $context_details['label']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $contexts; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generate select input with provided messenger options array. |
|
| 202 | + * |
|
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | + * labels. |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function get_messengers_select_input($messenger_options) |
|
| 209 | + { |
|
| 210 | + //if empty or just one value then just return an empty string |
|
| 211 | + if (empty($messenger_options) |
|
| 212 | + || ! is_array($messenger_options) |
|
| 213 | + || count($messenger_options) === 1 |
|
| 214 | + ) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + //merge in default |
|
| 218 | + $messenger_options = array_merge( |
|
| 219 | + array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | + $messenger_options |
|
| 221 | + ); |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | + $messenger_options, |
|
| 224 | + array( |
|
| 225 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | + 'html_class' => 'wide', |
|
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | + : 'none_selected' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + return $input->get_html_for_input(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Generate select input with provided message type options array. |
|
| 240 | + * |
|
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | + * message type labels |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_message_types_select_input($message_type_options) |
|
| 247 | + { |
|
| 248 | + //if empty or count of options is 1 then just return an empty string |
|
| 249 | + if (empty($message_type_options) |
|
| 250 | + || ! is_array($message_type_options) |
|
| 251 | + || count($message_type_options) === 1 |
|
| 252 | + ) { |
|
| 253 | + return ''; |
|
| 254 | + } |
|
| 255 | + //merge in default |
|
| 256 | + $message_type_options = array_merge( |
|
| 257 | + array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | + $message_type_options |
|
| 259 | + ); |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | + $message_type_options, |
|
| 262 | + array( |
|
| 263 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | + 'html_class' => 'wide', |
|
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | + : 'none_selected', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return $input->get_html_for_input(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generate select input with provide message type contexts array. |
|
| 278 | + * |
|
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | + * context label. |
|
| 281 | + * |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | + { |
|
| 286 | + //if empty or count of options is one then just return empty string |
|
| 287 | + if (empty($context_options) |
|
| 288 | + || ! is_array($context_options) |
|
| 289 | + || count($context_options) === 1 |
|
| 290 | + ) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 293 | + //merge in default |
|
| 294 | + $context_options = array_merge( |
|
| 295 | + array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | + $context_options |
|
| 297 | + ); |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | + $context_options, |
|
| 300 | + array( |
|
| 301 | + 'html_name' => 'ee_context_filter_by', |
|
| 302 | + 'html_id' => 'ee_context_filter_by', |
|
| 303 | + 'html_class' => 'wide', |
|
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | + : 'none_selected', |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + return $input->get_html_for_input(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _ajax_hooks() |
|
| 315 | + { |
|
| 316 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + protected function _define_page_props() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = $this->page_label; |
|
| 327 | + $this->_labels = array( |
|
| 328 | + 'buttons' => array( |
|
| 329 | + 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | + 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | + 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | + ), |
|
| 333 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | + * @access protected |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function _set_page_routes() |
|
| 344 | + { |
|
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | + ? $this->_req_data['GRP_ID'] |
|
| 347 | + : 0; |
|
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | + ? $this->_req_data['id'] |
|
| 350 | + : $grp_id; |
|
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | + ? $this->_req_data['MSG_ID'] |
|
| 353 | + : 0; |
|
| 354 | + |
|
| 355 | + $this->_page_routes = array( |
|
| 356 | + 'default' => array( |
|
| 357 | + 'func' => '_message_queue_list_table', |
|
| 358 | + 'capability' => 'ee_read_global_messages' |
|
| 359 | + ), |
|
| 360 | + 'global_mtps' => array( |
|
| 361 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | + 'capability' => 'ee_read_global_messages' |
|
| 363 | + ), |
|
| 364 | + 'custom_mtps' => array( |
|
| 365 | + 'func' => '_custom_mtps_preview', |
|
| 366 | + 'capability' => 'ee_read_messages' |
|
| 367 | + ), |
|
| 368 | + 'add_new_message_template' => array( |
|
| 369 | + 'func' => '_add_message_template', |
|
| 370 | + 'capability' => 'ee_edit_messages', |
|
| 371 | + 'noheader' => true |
|
| 372 | + ), |
|
| 373 | + 'edit_message_template' => array( |
|
| 374 | + 'func' => '_edit_message_template', |
|
| 375 | + 'capability' => 'ee_edit_message', |
|
| 376 | + 'obj_id' => $grp_id |
|
| 377 | + ), |
|
| 378 | + 'preview_message' => array( |
|
| 379 | + 'func' => '_preview_message', |
|
| 380 | + 'capability' => 'ee_read_message', |
|
| 381 | + 'obj_id' => $grp_id, |
|
| 382 | + 'noheader' => true, |
|
| 383 | + 'headers_sent_route' => 'display_preview_message' |
|
| 384 | + ), |
|
| 385 | + 'display_preview_message' => array( |
|
| 386 | + 'func' => '_display_preview_message', |
|
| 387 | + 'capability' => 'ee_read_message', |
|
| 388 | + 'obj_id' => $grp_id |
|
| 389 | + ), |
|
| 390 | + 'insert_message_template' => array( |
|
| 391 | + 'func' => '_insert_or_update_message_template', |
|
| 392 | + 'capability' => 'ee_edit_messages', |
|
| 393 | + 'args' => array('new_template' => true), |
|
| 394 | + 'noheader' => true |
|
| 395 | + ), |
|
| 396 | + 'update_message_template' => array( |
|
| 397 | + 'func' => '_insert_or_update_message_template', |
|
| 398 | + 'capability' => 'ee_edit_message', |
|
| 399 | + 'obj_id' => $grp_id, |
|
| 400 | + 'args' => array('new_template' => false), |
|
| 401 | + 'noheader' => true |
|
| 402 | + ), |
|
| 403 | + 'trash_message_template' => array( |
|
| 404 | + 'func' => '_trash_or_restore_message_template', |
|
| 405 | + 'capability' => 'ee_delete_message', |
|
| 406 | + 'obj_id' => $grp_id, |
|
| 407 | + 'args' => array('trash' => true, 'all' => true), |
|
| 408 | + 'noheader' => true |
|
| 409 | + ), |
|
| 410 | + 'trash_message_template_context' => array( |
|
| 411 | + 'func' => '_trash_or_restore_message_template', |
|
| 412 | + 'capability' => 'ee_delete_message', |
|
| 413 | + 'obj_id' => $grp_id, |
|
| 414 | + 'args' => array('trash' => true), |
|
| 415 | + 'noheader' => true |
|
| 416 | + ), |
|
| 417 | + 'restore_message_template' => array( |
|
| 418 | + 'func' => '_trash_or_restore_message_template', |
|
| 419 | + 'capability' => 'ee_delete_message', |
|
| 420 | + 'obj_id' => $grp_id, |
|
| 421 | + 'args' => array('trash' => false, 'all' => true), |
|
| 422 | + 'noheader' => true |
|
| 423 | + ), |
|
| 424 | + 'restore_message_template_context' => array( |
|
| 425 | + 'func' => '_trash_or_restore_message_template', |
|
| 426 | + 'capability' => 'ee_delete_message', |
|
| 427 | + 'obj_id' => $grp_id, |
|
| 428 | + 'args' => array('trash' => false), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'delete_message_template' => array( |
|
| 432 | + 'func' => '_delete_message_template', |
|
| 433 | + 'capability' => 'ee_delete_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'reset_to_default' => array( |
|
| 438 | + 'func' => '_reset_to_default_template', |
|
| 439 | + 'capability' => 'ee_edit_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'noheader' => true |
|
| 442 | + ), |
|
| 443 | + 'settings' => array( |
|
| 444 | + 'func' => '_settings', |
|
| 445 | + 'capability' => 'manage_options' |
|
| 446 | + ), |
|
| 447 | + 'update_global_settings' => array( |
|
| 448 | + 'func' => '_update_global_settings', |
|
| 449 | + 'capability' => 'manage_options', |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'generate_now' => array( |
|
| 453 | + 'func' => '_generate_now', |
|
| 454 | + 'capability' => 'ee_send_message', |
|
| 455 | + 'noheader' => true |
|
| 456 | + ), |
|
| 457 | + 'generate_and_send_now' => array( |
|
| 458 | + 'func' => '_generate_and_send_now', |
|
| 459 | + 'capability' => 'ee_send_message', |
|
| 460 | + 'noheader' => true |
|
| 461 | + ), |
|
| 462 | + 'queue_for_resending' => array( |
|
| 463 | + 'func' => '_queue_for_resending', |
|
| 464 | + 'capability' => 'ee_send_message', |
|
| 465 | + 'noheader' => true |
|
| 466 | + ), |
|
| 467 | + 'send_now' => array( |
|
| 468 | + 'func' => '_send_now', |
|
| 469 | + 'capability' => 'ee_send_message', |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'delete_ee_message' => array( |
|
| 473 | + 'func' => '_delete_ee_messages', |
|
| 474 | + 'capability' => 'ee_delete_message', |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'delete_ee_messages' => array( |
|
| 478 | + 'func' => '_delete_ee_messages', |
|
| 479 | + 'capability' => 'ee_delete_messages', |
|
| 480 | + 'noheader' => true, |
|
| 481 | + 'obj_id' => $msg_id |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + protected function _set_page_config() |
|
| 488 | + { |
|
| 489 | + $this->_page_config = array( |
|
| 490 | + 'default' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | + 'order' => 10 |
|
| 494 | + ), |
|
| 495 | + 'list_table' => 'EE_Message_List_Table', |
|
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | + 'require_nonce' => false |
|
| 498 | + ), |
|
| 499 | + 'global_mtps' => array( |
|
| 500 | + 'nav' => array( |
|
| 501 | + 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | + 'order' => 20 |
|
| 503 | + ), |
|
| 504 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | + 'help_tabs' => array( |
|
| 506 | + 'messages_overview_help_tab' => array( |
|
| 507 | + 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | + 'filename' => 'messages_overview' |
|
| 509 | + ), |
|
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | + 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | + ), |
|
| 514 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | + 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | + 'filename' => 'messages_overview_filters' |
|
| 517 | + ), |
|
| 518 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | + 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | + 'filename' => 'messages_overview_views' |
|
| 521 | + ), |
|
| 522 | + 'message_overview_message_types_help_tab' => array( |
|
| 523 | + 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | + 'filename' => 'messages_overview_types' |
|
| 525 | + ), |
|
| 526 | + 'messages_overview_messengers_help_tab' => array( |
|
| 527 | + 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | + 'filename' => 'messages_overview_messengers', |
|
| 529 | + ), |
|
| 530 | + 'messages_overview_other_help_tab' => array( |
|
| 531 | + 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | + 'filename' => 'messages_overview_other', |
|
| 533 | + ), |
|
| 534 | + ), |
|
| 535 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | + 'require_nonce' => false |
|
| 537 | + ), |
|
| 538 | + 'custom_mtps' => array( |
|
| 539 | + 'nav' => array( |
|
| 540 | + 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | + 'order' => 30 |
|
| 542 | + ), |
|
| 543 | + 'help_tabs' => array(), |
|
| 544 | + 'help_tour' => array(), |
|
| 545 | + 'require_nonce' => false |
|
| 546 | + ), |
|
| 547 | + 'add_new_message_template' => array( |
|
| 548 | + 'nav' => array( |
|
| 549 | + 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | + 'order' => 5, |
|
| 551 | + 'persistent' => false |
|
| 552 | + ), |
|
| 553 | + 'require_nonce' => false |
|
| 554 | + ), |
|
| 555 | + 'edit_message_template' => array( |
|
| 556 | + 'labels' => array( |
|
| 557 | + 'buttons' => array( |
|
| 558 | + 'reset' => __('Reset Templates'), |
|
| 559 | + ), |
|
| 560 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | + ), |
|
| 562 | + 'nav' => array( |
|
| 563 | + 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | + 'order' => 5, |
|
| 565 | + 'persistent' => false, |
|
| 566 | + 'url' => '' |
|
| 567 | + ), |
|
| 568 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | + 'has_metaboxes' => true, |
|
| 570 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | + 'help_tabs' => array( |
|
| 572 | + 'edit_message_template' => array( |
|
| 573 | + 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | + 'callback' => 'edit_message_template_help_tab' |
|
| 575 | + ), |
|
| 576 | + 'message_templates_help_tab' => array( |
|
| 577 | + 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | + 'filename' => 'messages_templates' |
|
| 579 | + ), |
|
| 580 | + 'message_template_shortcodes' => array( |
|
| 581 | + 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | + ), |
|
| 584 | + 'message_preview_help_tab' => array( |
|
| 585 | + 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | + 'filename' => 'messages_preview' |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + 'require_nonce' => false |
|
| 590 | + ), |
|
| 591 | + 'display_preview_message' => array( |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'url' => '', |
|
| 596 | + 'persistent' => false |
|
| 597 | + ), |
|
| 598 | + 'help_tabs' => array( |
|
| 599 | + 'preview_message' => array( |
|
| 600 | + 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | + 'callback' => 'preview_message_help_tab' |
|
| 602 | + ) |
|
| 603 | + ), |
|
| 604 | + 'require_nonce' => false |
|
| 605 | + ), |
|
| 606 | + 'settings' => array( |
|
| 607 | + 'nav' => array( |
|
| 608 | + 'label' => __('Settings', 'event_espresso'), |
|
| 609 | + 'order' => 40 |
|
| 610 | + ), |
|
| 611 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | + 'help_tabs' => array( |
|
| 613 | + 'messages_settings_help_tab' => array( |
|
| 614 | + 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | + 'filename' => 'messages_settings' |
|
| 616 | + ), |
|
| 617 | + 'messages_settings_message_types_help_tab' => array( |
|
| 618 | + 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | + 'filename' => 'messages_settings_message_types' |
|
| 620 | + ), |
|
| 621 | + 'messages_settings_messengers_help_tab' => array( |
|
| 622 | + 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | + 'filename' => 'messages_settings_messengers' |
|
| 624 | + ), |
|
| 625 | + ), |
|
| 626 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | + 'require_nonce' => false |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_screen_options() |
|
| 634 | + { |
|
| 635 | + //todo |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + protected function _add_screen_options_global_mtps() |
|
| 640 | + { |
|
| 641 | + /** |
|
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | + */ |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + protected function _add_screen_options_default() |
|
| 653 | + { |
|
| 654 | + $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | + $this->_per_page_screen_option(); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + //none of the below group are currently used for Messages |
|
| 660 | + protected function _add_feature_pointers() |
|
| 661 | + { |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + public function admin_init() |
|
| 665 | + { |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + public function admin_notices() |
|
| 669 | + { |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + public function admin_footer_scripts() |
|
| 673 | + { |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + public function messages_help_tab() |
|
| 678 | + { |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + public function messengers_help_tab() |
|
| 684 | + { |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function message_types_help_tab() |
|
| 690 | + { |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + public function messages_overview_help_tab() |
|
| 696 | + { |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + public function message_templates_help_tab() |
|
| 702 | + { |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + public function edit_message_template_help_tab() |
|
| 708 | + { |
|
| 709 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso') . '" />'; |
|
| 711 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso') . '" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso') . '" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso') . '" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso') . '" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | + $args); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + public function message_template_shortcodes_help_tab() |
|
| 725 | + { |
|
| 726 | + $this->_set_shortcodes(); |
|
| 727 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | + $args); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab() |
|
| 734 | - { |
|
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | - } |
|
| 733 | + public function preview_message_help_tab() |
|
| 734 | + { |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - |
|
| 739 | - public function settings_help_tab() |
|
| 740 | - { |
|
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 745 | - $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | - $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | - } |
|
| 738 | + |
|
| 739 | + public function settings_help_tab() |
|
| 740 | + { |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso') . '" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso') . '" />'; |
|
| 745 | + $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | + $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles() |
|
| 752 | - { |
|
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 751 | + public function load_scripts_styles() |
|
| 752 | + { |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | - } |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default() |
|
| 764 | - { |
|
| 765 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | - } |
|
| 763 | + public function load_scripts_styles_default() |
|
| 764 | + { |
|
| 765 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css) |
|
| 770 | - { |
|
| 771 | - //if we're on the edit_message_template route |
|
| 772 | - if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | - $message_type_name = $this->_active_message_type_name; |
|
| 769 | + public function wp_editor_css($mce_css) |
|
| 770 | + { |
|
| 771 | + //if we're on the edit_message_template route |
|
| 772 | + if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | + $message_type_name = $this->_active_message_type_name; |
|
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css |
|
| 776 | - //we need to get the css file location from the active messenger |
|
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | - 'wpeditor', $this->_variation); |
|
| 779 | - } |
|
| 775 | + //we're going to REPLACE the existing mce css |
|
| 776 | + //we need to get the css file location from the active messenger |
|
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | + 'wpeditor', $this->_variation); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return $mce_css; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - public function load_scripts_styles_edit_message_template() |
|
| 786 | - { |
|
| 787 | - |
|
| 788 | - $this->_set_shortcodes(); |
|
| 781 | + return $mce_css; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + public function load_scripts_styles_edit_message_template() |
|
| 786 | + { |
|
| 787 | + |
|
| 788 | + $this->_set_shortcodes(); |
|
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | - __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | - 'event_espresso'), |
|
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | - ); |
|
| 796 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | - 'event_espresso'); |
|
| 798 | - |
|
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | - EVENT_ESPRESSO_VERSION); |
|
| 801 | - |
|
| 802 | - wp_enqueue_script('ee_admin_js'); |
|
| 803 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | - |
|
| 805 | - //add in special css for tiny_mce |
|
| 806 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - public function load_scripts_styles_display_preview_message() |
|
| 811 | - { |
|
| 812 | - |
|
| 813 | - $this->_set_message_template_group(); |
|
| 814 | - |
|
| 815 | - if (isset($this->_req_data['messenger'])) { |
|
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - wp_enqueue_style('espresso_preview_css', |
|
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | - $this->_variation)); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - public function load_scripts_styles_settings() |
|
| 829 | - { |
|
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | - EVENT_ESPRESSO_VERSION); |
|
| 832 | - wp_enqueue_style('ee-text-links'); |
|
| 833 | - wp_enqueue_style('ee-message-settings'); |
|
| 834 | - |
|
| 835 | - wp_enqueue_script('ee-messages-settings'); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * set views array for List Table |
|
| 841 | - */ |
|
| 842 | - public function _set_list_table_views_global_mtps() |
|
| 843 | - { |
|
| 844 | - $this->_views = array( |
|
| 845 | - 'in_use' => array( |
|
| 846 | - 'slug' => 'in_use', |
|
| 847 | - 'label' => __('In Use', 'event_espresso'), |
|
| 848 | - 'count' => 0, |
|
| 849 | - 'bulk_action' => array( |
|
| 850 | - 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | - ) |
|
| 852 | - ) |
|
| 853 | - ); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * set views array for message queue list table |
|
| 859 | - */ |
|
| 860 | - public function _set_list_table_views_default() |
|
| 861 | - { |
|
| 862 | - EE_Registry::instance()->load_helper('Template'); |
|
| 863 | - |
|
| 864 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | - 'message_list_table_bulk_actions') |
|
| 866 | - ? array( |
|
| 867 | - 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | - 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | - 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | - 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | - ) |
|
| 872 | - : array(); |
|
| 873 | - |
|
| 874 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | - 'message_list_table_bulk_actions') |
|
| 876 | - ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | - : array(); |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - $this->_views = array( |
|
| 881 | - 'all' => array( |
|
| 882 | - 'slug' => 'all', |
|
| 883 | - 'label' => __('All', 'event_espresso'), |
|
| 884 | - 'count' => 0, |
|
| 885 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | - ) |
|
| 887 | - ); |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | - continue; |
|
| 893 | - } |
|
| 894 | - $status_bulk_actions = $common_bulk_actions; |
|
| 895 | - //unset bulk actions not applying to status |
|
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 897 | - switch ($status) { |
|
| 898 | - case EEM_Message::status_idle: |
|
| 899 | - case EEM_Message::status_resend: |
|
| 900 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | - break; |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | + __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | + 'event_espresso'), |
|
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | + ); |
|
| 796 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | + 'event_espresso'); |
|
| 798 | + |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | + EVENT_ESPRESSO_VERSION); |
|
| 801 | + |
|
| 802 | + wp_enqueue_script('ee_admin_js'); |
|
| 803 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | + |
|
| 805 | + //add in special css for tiny_mce |
|
| 806 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + public function load_scripts_styles_display_preview_message() |
|
| 811 | + { |
|
| 812 | + |
|
| 813 | + $this->_set_message_template_group(); |
|
| 814 | + |
|
| 815 | + if (isset($this->_req_data['messenger'])) { |
|
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + wp_enqueue_style('espresso_preview_css', |
|
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | + $this->_variation)); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + public function load_scripts_styles_settings() |
|
| 829 | + { |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | + EVENT_ESPRESSO_VERSION); |
|
| 832 | + wp_enqueue_style('ee-text-links'); |
|
| 833 | + wp_enqueue_style('ee-message-settings'); |
|
| 834 | + |
|
| 835 | + wp_enqueue_script('ee-messages-settings'); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * set views array for List Table |
|
| 841 | + */ |
|
| 842 | + public function _set_list_table_views_global_mtps() |
|
| 843 | + { |
|
| 844 | + $this->_views = array( |
|
| 845 | + 'in_use' => array( |
|
| 846 | + 'slug' => 'in_use', |
|
| 847 | + 'label' => __('In Use', 'event_espresso'), |
|
| 848 | + 'count' => 0, |
|
| 849 | + 'bulk_action' => array( |
|
| 850 | + 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | + ) |
|
| 852 | + ) |
|
| 853 | + ); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * set views array for message queue list table |
|
| 859 | + */ |
|
| 860 | + public function _set_list_table_views_default() |
|
| 861 | + { |
|
| 862 | + EE_Registry::instance()->load_helper('Template'); |
|
| 863 | + |
|
| 864 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | + 'message_list_table_bulk_actions') |
|
| 866 | + ? array( |
|
| 867 | + 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | + 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | + 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | + 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | + ) |
|
| 872 | + : array(); |
|
| 873 | + |
|
| 874 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | + 'message_list_table_bulk_actions') |
|
| 876 | + ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | + : array(); |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + $this->_views = array( |
|
| 881 | + 'all' => array( |
|
| 882 | + 'slug' => 'all', |
|
| 883 | + 'label' => __('All', 'event_espresso'), |
|
| 884 | + 'count' => 0, |
|
| 885 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | + ) |
|
| 887 | + ); |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | + continue; |
|
| 893 | + } |
|
| 894 | + $status_bulk_actions = $common_bulk_actions; |
|
| 895 | + //unset bulk actions not applying to status |
|
| 896 | + if (! empty($status_bulk_actions)) { |
|
| 897 | + switch ($status) { |
|
| 898 | + case EEM_Message::status_idle: |
|
| 899 | + case EEM_Message::status_resend: |
|
| 900 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | + break; |
|
| 902 | 902 | |
| 903 | - case EEM_Message::status_failed: |
|
| 904 | - case EEM_Message::status_debug_only: |
|
| 905 | - case EEM_Message::status_messenger_executing: |
|
| 906 | - $status_bulk_actions = array(); |
|
| 907 | - break; |
|
| 903 | + case EEM_Message::status_failed: |
|
| 904 | + case EEM_Message::status_debug_only: |
|
| 905 | + case EEM_Message::status_messenger_executing: |
|
| 906 | + $status_bulk_actions = array(); |
|
| 907 | + break; |
|
| 908 | 908 | |
| 909 | - case EEM_Message::status_incomplete: |
|
| 910 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 911 | - break; |
|
| 909 | + case EEM_Message::status_incomplete: |
|
| 910 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 911 | + break; |
|
| 912 | 912 | |
| 913 | - case EEM_Message::status_retry: |
|
| 914 | - case EEM_Message::status_sent: |
|
| 915 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 916 | - break; |
|
| 917 | - } |
|
| 918 | - } |
|
| 913 | + case EEM_Message::status_retry: |
|
| 914 | + case EEM_Message::status_sent: |
|
| 915 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 916 | + break; |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | 919 | |
| 920 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 922 | - continue; |
|
| 923 | - } |
|
| 920 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 921 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 922 | + continue; |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | - $this->_views[strtolower($status)] = array( |
|
| 926 | - 'slug' => strtolower($status), |
|
| 927 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 928 | - 'count' => 0, |
|
| 929 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 930 | - ); |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - protected function _ee_default_messages_overview_list_table() |
|
| 936 | - { |
|
| 937 | - $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 938 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - protected function _message_queue_list_table() |
|
| 943 | - { |
|
| 944 | - $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 945 | - $this->_template_args['per_column'] = 6; |
|
| 946 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 948 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - protected function _message_legend_items() |
|
| 953 | - { |
|
| 954 | - |
|
| 955 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 956 | - $action_items = array(); |
|
| 957 | - |
|
| 958 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 959 | - if ($action_item === 'see_notifications_for') { |
|
| 960 | - continue; |
|
| 961 | - } |
|
| 962 | - $action_items[$action_item] = array( |
|
| 963 | - 'class' => $action_details['css_class'], |
|
| 964 | - 'desc' => $action_details['label'] |
|
| 965 | - ); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /** @type array $status_items status legend setup */ |
|
| 969 | - $status_items = array( |
|
| 970 | - 'sent_status' => array( |
|
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 972 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 973 | - ), |
|
| 974 | - 'idle_status' => array( |
|
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 976 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 977 | - ), |
|
| 978 | - 'failed_status' => array( |
|
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 980 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 981 | - ), |
|
| 982 | - 'messenger_executing_status' => array( |
|
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 984 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 985 | - ), |
|
| 986 | - 'resend_status' => array( |
|
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 988 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 989 | - ), |
|
| 990 | - 'incomplete_status' => array( |
|
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 992 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 993 | - ), |
|
| 994 | - 'retry_status' => array( |
|
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 996 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 997 | - ) |
|
| 998 | - ); |
|
| 999 | - if (EEM_Message::debug()) { |
|
| 1000 | - $status_items['debug_only_status'] = array( |
|
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1002 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1003 | - ); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - return array_merge($action_items, $status_items); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - protected function _custom_mtps_preview() |
|
| 1011 | - { |
|
| 1012 | - $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1017 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * get_message_templates |
|
| 1023 | - * This gets all the message templates for listing on the overview list. |
|
| 1024 | - * |
|
| 1025 | - * @access public |
|
| 1026 | - * |
|
| 1027 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1028 | - * @param string $type the current _view we're getting templates for |
|
| 1029 | - * @param bool $count return count? |
|
| 1030 | - * @param bool $all disregard any paging info (get all data); |
|
| 1031 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1032 | - * |
|
| 1033 | - * @return array |
|
| 1034 | - */ |
|
| 1035 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1036 | - { |
|
| 1037 | - |
|
| 1038 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1039 | - |
|
| 1040 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1041 | - $orderby = $this->_req_data['orderby']; |
|
| 1042 | - |
|
| 1043 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1044 | - |
|
| 1045 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1046 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1047 | - |
|
| 1048 | - $offset = ($current_page - 1) * $per_page; |
|
| 1049 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - //options will match what is in the _views array property |
|
| 1053 | - switch ($type) { |
|
| 925 | + $this->_views[strtolower($status)] = array( |
|
| 926 | + 'slug' => strtolower($status), |
|
| 927 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 928 | + 'count' => 0, |
|
| 929 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + protected function _ee_default_messages_overview_list_table() |
|
| 936 | + { |
|
| 937 | + $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 938 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + protected function _message_queue_list_table() |
|
| 943 | + { |
|
| 944 | + $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 945 | + $this->_template_args['per_column'] = 6; |
|
| 946 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 948 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + protected function _message_legend_items() |
|
| 953 | + { |
|
| 954 | + |
|
| 955 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 956 | + $action_items = array(); |
|
| 957 | + |
|
| 958 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 959 | + if ($action_item === 'see_notifications_for') { |
|
| 960 | + continue; |
|
| 961 | + } |
|
| 962 | + $action_items[$action_item] = array( |
|
| 963 | + 'class' => $action_details['css_class'], |
|
| 964 | + 'desc' => $action_details['label'] |
|
| 965 | + ); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** @type array $status_items status legend setup */ |
|
| 969 | + $status_items = array( |
|
| 970 | + 'sent_status' => array( |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 972 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 973 | + ), |
|
| 974 | + 'idle_status' => array( |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 976 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 977 | + ), |
|
| 978 | + 'failed_status' => array( |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 980 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 981 | + ), |
|
| 982 | + 'messenger_executing_status' => array( |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 984 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 985 | + ), |
|
| 986 | + 'resend_status' => array( |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 988 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 989 | + ), |
|
| 990 | + 'incomplete_status' => array( |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 992 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 993 | + ), |
|
| 994 | + 'retry_status' => array( |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 996 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 997 | + ) |
|
| 998 | + ); |
|
| 999 | + if (EEM_Message::debug()) { |
|
| 1000 | + $status_items['debug_only_status'] = array( |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1002 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1003 | + ); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + return array_merge($action_items, $status_items); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + protected function _custom_mtps_preview() |
|
| 1011 | + { |
|
| 1012 | + $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso') . '" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso') . '</strong>'; |
|
| 1017 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * get_message_templates |
|
| 1023 | + * This gets all the message templates for listing on the overview list. |
|
| 1024 | + * |
|
| 1025 | + * @access public |
|
| 1026 | + * |
|
| 1027 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1028 | + * @param string $type the current _view we're getting templates for |
|
| 1029 | + * @param bool $count return count? |
|
| 1030 | + * @param bool $all disregard any paging info (get all data); |
|
| 1031 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1032 | + * |
|
| 1033 | + * @return array |
|
| 1034 | + */ |
|
| 1035 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1036 | + { |
|
| 1037 | + |
|
| 1038 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1039 | + |
|
| 1040 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1041 | + $orderby = $this->_req_data['orderby']; |
|
| 1042 | + |
|
| 1043 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1044 | + |
|
| 1045 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1046 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1047 | + |
|
| 1048 | + $offset = ($current_page - 1) * $per_page; |
|
| 1049 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + //options will match what is in the _views array property |
|
| 1053 | + switch ($type) { |
|
| 1054 | 1054 | |
| 1055 | - case 'in_use': |
|
| 1056 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1057 | - break; |
|
| 1055 | + case 'in_use': |
|
| 1056 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1057 | + break; |
|
| 1058 | 1058 | |
| 1059 | - default: |
|
| 1060 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1059 | + default: |
|
| 1060 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1061 | 1061 | |
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - return $templates; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - /** |
|
| 1069 | - * filters etc might need a list of installed message_types |
|
| 1070 | - * @return array an array of message type objects |
|
| 1071 | - */ |
|
| 1072 | - public function get_installed_message_types() |
|
| 1073 | - { |
|
| 1074 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1075 | - $installed = array(); |
|
| 1076 | - |
|
| 1077 | - foreach ($installed_message_types as $message_type) { |
|
| 1078 | - $installed[$message_type->name] = $message_type; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - return $installed; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * _add_message_template |
|
| 1087 | - * |
|
| 1088 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1089 | - * |
|
| 1090 | - * @param string $message_type |
|
| 1091 | - * @param string $messenger |
|
| 1092 | - * @param string $GRP_ID |
|
| 1093 | - * |
|
| 1094 | - * @throws EE_error |
|
| 1095 | - */ |
|
| 1096 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1097 | - { |
|
| 1098 | - //set values override any request data |
|
| 1099 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1100 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1101 | - |
|
| 1102 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1103 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1104 | - |
|
| 1105 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1106 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1107 | - |
|
| 1108 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1109 | - if (empty($message_type) || empty($messenger)) { |
|
| 1110 | - throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1111 | - 'event_espresso')); |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1115 | - if (empty($GRP_ID)) { |
|
| 1116 | - throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1117 | - 'event_espresso')); |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - //let's just make sure the template gets generated! |
|
| 1121 | - |
|
| 1122 | - //we need to reassign some variables for what the insert is expecting |
|
| 1123 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1124 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1125 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1126 | - $this->_insert_or_update_message_template(true); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * public wrapper for the _add_message_template method |
|
| 1132 | - * |
|
| 1133 | - * @param string $message_type message type slug |
|
| 1134 | - * @param string $messenger messenger slug |
|
| 1135 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1136 | - * off of. |
|
| 1137 | - */ |
|
| 1138 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1139 | - { |
|
| 1140 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * _edit_message_template |
|
| 1146 | - * |
|
| 1147 | - * @access protected |
|
| 1148 | - * @return void |
|
| 1149 | - */ |
|
| 1150 | - protected function _edit_message_template() |
|
| 1151 | - { |
|
| 1152 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1153 | - $template_fields = ''; |
|
| 1154 | - $sidebar_fields = ''; |
|
| 1155 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1156 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1157 | - |
|
| 1158 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1159 | - ? absint($this->_req_data['id']) |
|
| 1160 | - : false; |
|
| 1161 | - |
|
| 1162 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1163 | - $message_template_group = $this->_message_template_group; |
|
| 1164 | - $c_label = $message_template_group->context_label(); |
|
| 1165 | - $c_config = $message_template_group->contexts_config(); |
|
| 1166 | - |
|
| 1167 | - reset($c_config); |
|
| 1168 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1169 | - ? strtolower($this->_req_data['context']) |
|
| 1170 | - : key($c_config); |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - if (empty($GRP_ID)) { |
|
| 1174 | - $action = 'insert_message_template'; |
|
| 1175 | - //$button_both = false; |
|
| 1176 | - //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1177 | - //$button_actions = array('something_different'); |
|
| 1178 | - //$referrer = false; |
|
| 1179 | - $edit_message_template_form_url = add_query_arg( |
|
| 1180 | - array('action' => $action, 'noheader' => true), |
|
| 1181 | - EE_MSG_ADMIN_URL |
|
| 1182 | - ); |
|
| 1183 | - } else { |
|
| 1184 | - $action = 'update_message_template'; |
|
| 1185 | - //$button_both = true; |
|
| 1186 | - //$button_text = array(); |
|
| 1187 | - //$button_actions = array(); |
|
| 1188 | - //$referrer = $this->_admin_base_url; |
|
| 1189 | - $edit_message_template_form_url = add_query_arg( |
|
| 1190 | - array('action' => $action, 'noheader' => true), |
|
| 1191 | - EE_MSG_ADMIN_URL |
|
| 1192 | - ); |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - //set active messenger for this view |
|
| 1196 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1197 | - $message_template_group->messenger() |
|
| 1198 | - ); |
|
| 1199 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1200 | - |
|
| 1201 | - |
|
| 1202 | - //Do we have any validation errors? |
|
| 1203 | - $validators = $this->_get_transient(); |
|
| 1204 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - //we need to assemble the title from Various details |
|
| 1208 | - $context_label = sprintf( |
|
| 1209 | - __('(%s %s)', 'event_espresso'), |
|
| 1210 | - $c_config[$context]['label'], |
|
| 1211 | - ucwords($c_label['label']) |
|
| 1212 | - ); |
|
| 1213 | - |
|
| 1214 | - $title = sprintf( |
|
| 1215 | - __(' %s %s Template %s', 'event_espresso'), |
|
| 1216 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1217 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1218 | - $context_label |
|
| 1219 | - ); |
|
| 1220 | - |
|
| 1221 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1222 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1223 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1227 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1228 | - $message_template_group->messenger(), |
|
| 1229 | - $message_template_group->message_type() |
|
| 1230 | - ); |
|
| 1231 | - |
|
| 1232 | - if ( ! $template_field_structure) { |
|
| 1233 | - $template_field_structure = false; |
|
| 1234 | - $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1235 | - 'event_espresso'); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - $message_templates = $message_template_group->context_templates(); |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1243 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1244 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1245 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1250 | - if ( ! empty($template_field_structure)) { |
|
| 1251 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1252 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1253 | - if ($template_field == 'extra') { |
|
| 1254 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1255 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1256 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1257 | - $content = $message_template instanceof EE_Message_Template |
|
| 1258 | - ? $message_template->get('MTP_content') |
|
| 1259 | - : ''; |
|
| 1260 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1261 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1262 | - $continue = false; |
|
| 1263 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1266 | - $continue = true; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - if ($continue) { |
|
| 1270 | - continue; |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + return $templates; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + /** |
|
| 1069 | + * filters etc might need a list of installed message_types |
|
| 1070 | + * @return array an array of message type objects |
|
| 1071 | + */ |
|
| 1072 | + public function get_installed_message_types() |
|
| 1073 | + { |
|
| 1074 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1075 | + $installed = array(); |
|
| 1076 | + |
|
| 1077 | + foreach ($installed_message_types as $message_type) { |
|
| 1078 | + $installed[$message_type->name] = $message_type; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + return $installed; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * _add_message_template |
|
| 1087 | + * |
|
| 1088 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1089 | + * |
|
| 1090 | + * @param string $message_type |
|
| 1091 | + * @param string $messenger |
|
| 1092 | + * @param string $GRP_ID |
|
| 1093 | + * |
|
| 1094 | + * @throws EE_error |
|
| 1095 | + */ |
|
| 1096 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1097 | + { |
|
| 1098 | + //set values override any request data |
|
| 1099 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1100 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1101 | + |
|
| 1102 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1103 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1104 | + |
|
| 1105 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1106 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1107 | + |
|
| 1108 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1109 | + if (empty($message_type) || empty($messenger)) { |
|
| 1110 | + throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1111 | + 'event_espresso')); |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1115 | + if (empty($GRP_ID)) { |
|
| 1116 | + throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1117 | + 'event_espresso')); |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + //let's just make sure the template gets generated! |
|
| 1121 | + |
|
| 1122 | + //we need to reassign some variables for what the insert is expecting |
|
| 1123 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1124 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1125 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1126 | + $this->_insert_or_update_message_template(true); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * public wrapper for the _add_message_template method |
|
| 1132 | + * |
|
| 1133 | + * @param string $message_type message type slug |
|
| 1134 | + * @param string $messenger messenger slug |
|
| 1135 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1136 | + * off of. |
|
| 1137 | + */ |
|
| 1138 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1139 | + { |
|
| 1140 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * _edit_message_template |
|
| 1146 | + * |
|
| 1147 | + * @access protected |
|
| 1148 | + * @return void |
|
| 1149 | + */ |
|
| 1150 | + protected function _edit_message_template() |
|
| 1151 | + { |
|
| 1152 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1153 | + $template_fields = ''; |
|
| 1154 | + $sidebar_fields = ''; |
|
| 1155 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1156 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1157 | + |
|
| 1158 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1159 | + ? absint($this->_req_data['id']) |
|
| 1160 | + : false; |
|
| 1161 | + |
|
| 1162 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1163 | + $message_template_group = $this->_message_template_group; |
|
| 1164 | + $c_label = $message_template_group->context_label(); |
|
| 1165 | + $c_config = $message_template_group->contexts_config(); |
|
| 1166 | + |
|
| 1167 | + reset($c_config); |
|
| 1168 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1169 | + ? strtolower($this->_req_data['context']) |
|
| 1170 | + : key($c_config); |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + if (empty($GRP_ID)) { |
|
| 1174 | + $action = 'insert_message_template'; |
|
| 1175 | + //$button_both = false; |
|
| 1176 | + //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1177 | + //$button_actions = array('something_different'); |
|
| 1178 | + //$referrer = false; |
|
| 1179 | + $edit_message_template_form_url = add_query_arg( |
|
| 1180 | + array('action' => $action, 'noheader' => true), |
|
| 1181 | + EE_MSG_ADMIN_URL |
|
| 1182 | + ); |
|
| 1183 | + } else { |
|
| 1184 | + $action = 'update_message_template'; |
|
| 1185 | + //$button_both = true; |
|
| 1186 | + //$button_text = array(); |
|
| 1187 | + //$button_actions = array(); |
|
| 1188 | + //$referrer = $this->_admin_base_url; |
|
| 1189 | + $edit_message_template_form_url = add_query_arg( |
|
| 1190 | + array('action' => $action, 'noheader' => true), |
|
| 1191 | + EE_MSG_ADMIN_URL |
|
| 1192 | + ); |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + //set active messenger for this view |
|
| 1196 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1197 | + $message_template_group->messenger() |
|
| 1198 | + ); |
|
| 1199 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1200 | + |
|
| 1201 | + |
|
| 1202 | + //Do we have any validation errors? |
|
| 1203 | + $validators = $this->_get_transient(); |
|
| 1204 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + //we need to assemble the title from Various details |
|
| 1208 | + $context_label = sprintf( |
|
| 1209 | + __('(%s %s)', 'event_espresso'), |
|
| 1210 | + $c_config[$context]['label'], |
|
| 1211 | + ucwords($c_label['label']) |
|
| 1212 | + ); |
|
| 1213 | + |
|
| 1214 | + $title = sprintf( |
|
| 1215 | + __(' %s %s Template %s', 'event_espresso'), |
|
| 1216 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1217 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1218 | + $context_label |
|
| 1219 | + ); |
|
| 1220 | + |
|
| 1221 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1222 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1223 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1227 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1228 | + $message_template_group->messenger(), |
|
| 1229 | + $message_template_group->message_type() |
|
| 1230 | + ); |
|
| 1231 | + |
|
| 1232 | + if ( ! $template_field_structure) { |
|
| 1233 | + $template_field_structure = false; |
|
| 1234 | + $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1235 | + 'event_espresso'); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + $message_templates = $message_template_group->context_templates(); |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1243 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1244 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1245 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1250 | + if ( ! empty($template_field_structure)) { |
|
| 1251 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1252 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1253 | + if ($template_field == 'extra') { |
|
| 1254 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1255 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1256 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1257 | + $content = $message_template instanceof EE_Message_Template |
|
| 1258 | + ? $message_template->get('MTP_content') |
|
| 1259 | + : ''; |
|
| 1260 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1261 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1262 | + $continue = false; |
|
| 1263 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1264 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1266 | + $continue = true; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + if ($continue) { |
|
| 1270 | + continue; |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1275 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1277 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1274 | + $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1275 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1277 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1278 | 1278 | |
| 1279 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1280 | - && in_array($extra_field, $v_fields) |
|
| 1281 | - && |
|
| 1282 | - ( |
|
| 1283 | - is_array($validators[$extra_field]) |
|
| 1284 | - && isset($validators[$extra_field]['msg']) |
|
| 1285 | - ) |
|
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1287 | - : $css_class; |
|
| 1279 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1280 | + && in_array($extra_field, $v_fields) |
|
| 1281 | + && |
|
| 1282 | + ( |
|
| 1283 | + is_array($validators[$extra_field]) |
|
| 1284 | + && isset($validators[$extra_field]['msg']) |
|
| 1285 | + ) |
|
| 1286 | + ? 'validate-error ' . $css_class |
|
| 1287 | + : $css_class; |
|
| 1288 | 1288 | |
| 1289 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1290 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1291 | - : ''; |
|
| 1289 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1290 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1291 | + : ''; |
|
| 1292 | 1292 | |
| 1293 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1294 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1293 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1294 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1297 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1298 | 1298 | |
| 1299 | - //shortcode selector |
|
| 1300 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1301 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1302 | - $field_name_to_use, |
|
| 1303 | - $field_id |
|
| 1304 | - ); |
|
| 1299 | + //shortcode selector |
|
| 1300 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1301 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1302 | + $field_name_to_use, |
|
| 1303 | + $field_id |
|
| 1304 | + ); |
|
| 1305 | 1305 | |
| 1306 | - if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1307 | - //we want to decode the entities |
|
| 1308 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1309 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1310 | - ); |
|
| 1306 | + if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1307 | + //we want to decode the entities |
|
| 1308 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1309 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1310 | + ); |
|
| 1311 | 1311 | |
| 1312 | - }/**/ |
|
| 1313 | - } |
|
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1312 | + }/**/ |
|
| 1313 | + } |
|
| 1314 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1316 | 1316 | |
| 1317 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1319 | - 'label' => null, |
|
| 1320 | - 'input' => 'hidden', |
|
| 1321 | - 'type' => 'int', |
|
| 1322 | - 'required' => false, |
|
| 1323 | - 'validation' => false, |
|
| 1324 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1325 | - 'css_class' => '', |
|
| 1326 | - 'format' => '%d', |
|
| 1327 | - 'db-col' => 'MTP_ID' |
|
| 1328 | - ); |
|
| 1317 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1318 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1319 | + 'label' => null, |
|
| 1320 | + 'input' => 'hidden', |
|
| 1321 | + 'type' => 'int', |
|
| 1322 | + 'required' => false, |
|
| 1323 | + 'validation' => false, |
|
| 1324 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1325 | + 'css_class' => '', |
|
| 1326 | + 'format' => '%d', |
|
| 1327 | + 'db-col' => 'MTP_ID' |
|
| 1328 | + ); |
|
| 1329 | 1329 | |
| 1330 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1332 | - 'label' => null, |
|
| 1333 | - 'input' => 'hidden', |
|
| 1334 | - 'type' => 'string', |
|
| 1335 | - 'required' => false, |
|
| 1336 | - 'validation' => true, |
|
| 1337 | - 'value' => $reference_field, |
|
| 1338 | - 'css_class' => '', |
|
| 1339 | - 'format' => '%s', |
|
| 1340 | - 'db-col' => 'MTP_template_field' |
|
| 1341 | - ); |
|
| 1342 | - } |
|
| 1343 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1344 | - } else { |
|
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1346 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1348 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1349 | - ? $message_templates[$context][$template_field] |
|
| 1350 | - : null; |
|
| 1351 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1352 | - && is_array($message_templates[$context]) |
|
| 1353 | - && $message_template instanceof EE_Message_Template |
|
| 1354 | - ? $message_template->get('MTP_content') |
|
| 1355 | - : ''; |
|
| 1330 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1331 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1332 | + 'label' => null, |
|
| 1333 | + 'input' => 'hidden', |
|
| 1334 | + 'type' => 'string', |
|
| 1335 | + 'required' => false, |
|
| 1336 | + 'validation' => true, |
|
| 1337 | + 'value' => $reference_field, |
|
| 1338 | + 'css_class' => '', |
|
| 1339 | + 'format' => '%s', |
|
| 1340 | + 'db-col' => 'MTP_template_field' |
|
| 1341 | + ); |
|
| 1342 | + } |
|
| 1343 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1344 | + } else { |
|
| 1345 | + $field_id = $template_field . '-content'; |
|
| 1346 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1348 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1349 | + ? $message_templates[$context][$template_field] |
|
| 1350 | + : null; |
|
| 1351 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1352 | + && is_array($message_templates[$context]) |
|
| 1353 | + && $message_template instanceof EE_Message_Template |
|
| 1354 | + ? $message_template->get('MTP_content') |
|
| 1355 | + : ''; |
|
| 1356 | 1356 | |
| 1357 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1358 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1359 | - ? $validators[$template_field]['value'] |
|
| 1360 | - : $template_form_fields[$field_id]['value']; |
|
| 1357 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1358 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1359 | + ? $validators[$template_field]['value'] |
|
| 1360 | + : $template_form_fields[$field_id]['value']; |
|
| 1361 | 1361 | |
| 1362 | 1362 | |
| 1363 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1364 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1365 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1366 | - && in_array($template_field, $v_fields) |
|
| 1367 | - && isset($validators[$template_field]['msg']) |
|
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1369 | - : $css_class; |
|
| 1363 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1364 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1365 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1366 | + && in_array($template_field, $v_fields) |
|
| 1367 | + && isset($validators[$template_field]['msg']) |
|
| 1368 | + ? 'validate-error ' . $css_class |
|
| 1369 | + : $css_class; |
|
| 1370 | 1370 | |
| 1371 | - //shortcode selector |
|
| 1372 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1373 | - $template_field, $field_id |
|
| 1374 | - ); |
|
| 1375 | - } |
|
| 1371 | + //shortcode selector |
|
| 1372 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1373 | + $template_field, $field_id |
|
| 1374 | + ); |
|
| 1375 | + } |
|
| 1376 | 1376 | |
| 1377 | - //k took care of content field(s) now let's take care of others. |
|
| 1377 | + //k took care of content field(s) now let's take care of others. |
|
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1381 | 1381 | |
| 1382 | - //foreach template field there are actually two form fields created |
|
| 1383 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1385 | - 'label' => null, |
|
| 1386 | - 'input' => 'hidden', |
|
| 1387 | - 'type' => 'int', |
|
| 1388 | - 'required' => false, |
|
| 1389 | - 'validation' => true, |
|
| 1390 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1391 | - 'css_class' => '', |
|
| 1392 | - 'format' => '%d', |
|
| 1393 | - 'db-col' => 'MTP_ID' |
|
| 1394 | - ); |
|
| 1382 | + //foreach template field there are actually two form fields created |
|
| 1383 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1384 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1385 | + 'label' => null, |
|
| 1386 | + 'input' => 'hidden', |
|
| 1387 | + 'type' => 'int', |
|
| 1388 | + 'required' => false, |
|
| 1389 | + 'validation' => true, |
|
| 1390 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1391 | + 'css_class' => '', |
|
| 1392 | + 'format' => '%d', |
|
| 1393 | + 'db-col' => 'MTP_ID' |
|
| 1394 | + ); |
|
| 1395 | 1395 | |
| 1396 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1398 | - 'label' => null, |
|
| 1399 | - 'input' => 'hidden', |
|
| 1400 | - 'type' => 'string', |
|
| 1401 | - 'required' => false, |
|
| 1402 | - 'validation' => true, |
|
| 1403 | - 'value' => $template_field, |
|
| 1404 | - 'css_class' => '', |
|
| 1405 | - 'format' => '%s', |
|
| 1406 | - 'db-col' => 'MTP_template_field' |
|
| 1407 | - ); |
|
| 1396 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1397 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1398 | + 'label' => null, |
|
| 1399 | + 'input' => 'hidden', |
|
| 1400 | + 'type' => 'string', |
|
| 1401 | + 'required' => false, |
|
| 1402 | + 'validation' => true, |
|
| 1403 | + 'value' => $template_field, |
|
| 1404 | + 'css_class' => '', |
|
| 1405 | + 'format' => '%s', |
|
| 1406 | + 'db-col' => 'MTP_template_field' |
|
| 1407 | + ); |
|
| 1408 | 1408 | |
| 1409 | - } |
|
| 1409 | + } |
|
| 1410 | 1410 | |
| 1411 | - //add other fields |
|
| 1412 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1413 | - 'name' => 'MTP_context', |
|
| 1414 | - 'label' => null, |
|
| 1415 | - 'input' => 'hidden', |
|
| 1416 | - 'type' => 'string', |
|
| 1417 | - 'required' => false, |
|
| 1418 | - 'validation' => true, |
|
| 1419 | - 'value' => $context, |
|
| 1420 | - 'css_class' => '', |
|
| 1421 | - 'format' => '%s', |
|
| 1422 | - 'db-col' => 'MTP_context' |
|
| 1423 | - ); |
|
| 1411 | + //add other fields |
|
| 1412 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1413 | + 'name' => 'MTP_context', |
|
| 1414 | + 'label' => null, |
|
| 1415 | + 'input' => 'hidden', |
|
| 1416 | + 'type' => 'string', |
|
| 1417 | + 'required' => false, |
|
| 1418 | + 'validation' => true, |
|
| 1419 | + 'value' => $context, |
|
| 1420 | + 'css_class' => '', |
|
| 1421 | + 'format' => '%s', |
|
| 1422 | + 'db-col' => 'MTP_context' |
|
| 1423 | + ); |
|
| 1424 | 1424 | |
| 1425 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1426 | - 'name' => 'GRP_ID', |
|
| 1427 | - 'label' => null, |
|
| 1428 | - 'input' => 'hidden', |
|
| 1429 | - 'type' => 'int', |
|
| 1430 | - 'required' => false, |
|
| 1431 | - 'validation' => true, |
|
| 1432 | - 'value' => $GRP_ID, |
|
| 1433 | - 'css_class' => '', |
|
| 1434 | - 'format' => '%d', |
|
| 1435 | - 'db-col' => 'GRP_ID' |
|
| 1436 | - ); |
|
| 1425 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1426 | + 'name' => 'GRP_ID', |
|
| 1427 | + 'label' => null, |
|
| 1428 | + 'input' => 'hidden', |
|
| 1429 | + 'type' => 'int', |
|
| 1430 | + 'required' => false, |
|
| 1431 | + 'validation' => true, |
|
| 1432 | + 'value' => $GRP_ID, |
|
| 1433 | + 'css_class' => '', |
|
| 1434 | + 'format' => '%d', |
|
| 1435 | + 'db-col' => 'GRP_ID' |
|
| 1436 | + ); |
|
| 1437 | 1437 | |
| 1438 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1439 | - 'name' => 'MTP_messenger', |
|
| 1440 | - 'label' => null, |
|
| 1441 | - 'input' => 'hidden', |
|
| 1442 | - 'type' => 'string', |
|
| 1443 | - 'required' => false, |
|
| 1444 | - 'validation' => true, |
|
| 1445 | - 'value' => $message_template_group->messenger(), |
|
| 1446 | - 'css_class' => '', |
|
| 1447 | - 'format' => '%s', |
|
| 1448 | - 'db-col' => 'MTP_messenger' |
|
| 1449 | - ); |
|
| 1438 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1439 | + 'name' => 'MTP_messenger', |
|
| 1440 | + 'label' => null, |
|
| 1441 | + 'input' => 'hidden', |
|
| 1442 | + 'type' => 'string', |
|
| 1443 | + 'required' => false, |
|
| 1444 | + 'validation' => true, |
|
| 1445 | + 'value' => $message_template_group->messenger(), |
|
| 1446 | + 'css_class' => '', |
|
| 1447 | + 'format' => '%s', |
|
| 1448 | + 'db-col' => 'MTP_messenger' |
|
| 1449 | + ); |
|
| 1450 | 1450 | |
| 1451 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1452 | - 'name' => 'MTP_message_type', |
|
| 1453 | - 'label' => null, |
|
| 1454 | - 'input' => 'hidden', |
|
| 1455 | - 'type' => 'string', |
|
| 1456 | - 'required' => false, |
|
| 1457 | - 'validation' => true, |
|
| 1458 | - 'value' => $message_template_group->message_type(), |
|
| 1459 | - 'css_class' => '', |
|
| 1460 | - 'format' => '%s', |
|
| 1461 | - 'db-col' => 'MTP_message_type' |
|
| 1462 | - ); |
|
| 1451 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1452 | + 'name' => 'MTP_message_type', |
|
| 1453 | + 'label' => null, |
|
| 1454 | + 'input' => 'hidden', |
|
| 1455 | + 'type' => 'string', |
|
| 1456 | + 'required' => false, |
|
| 1457 | + 'validation' => true, |
|
| 1458 | + 'value' => $message_template_group->message_type(), |
|
| 1459 | + 'css_class' => '', |
|
| 1460 | + 'format' => '%s', |
|
| 1461 | + 'db-col' => 'MTP_message_type' |
|
| 1462 | + ); |
|
| 1463 | 1463 | |
| 1464 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1465 | - 'name' => 'MTP_is_global', |
|
| 1466 | - 'label' => __('Global Template', 'event_espresso'), |
|
| 1467 | - 'input' => 'hidden', |
|
| 1468 | - 'type' => 'int', |
|
| 1469 | - 'required' => false, |
|
| 1470 | - 'validation' => true, |
|
| 1471 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1472 | - 'css_class' => '', |
|
| 1473 | - 'format' => '%d', |
|
| 1474 | - 'db-col' => 'MTP_is_global' |
|
| 1475 | - ); |
|
| 1464 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1465 | + 'name' => 'MTP_is_global', |
|
| 1466 | + 'label' => __('Global Template', 'event_espresso'), |
|
| 1467 | + 'input' => 'hidden', |
|
| 1468 | + 'type' => 'int', |
|
| 1469 | + 'required' => false, |
|
| 1470 | + 'validation' => true, |
|
| 1471 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1472 | + 'css_class' => '', |
|
| 1473 | + 'format' => '%d', |
|
| 1474 | + 'db-col' => 'MTP_is_global' |
|
| 1475 | + ); |
|
| 1476 | 1476 | |
| 1477 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1478 | - 'name' => 'MTP_is_override', |
|
| 1479 | - 'label' => __('Override all custom', 'event_espresso'), |
|
| 1480 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1481 | - 'type' => 'int', |
|
| 1482 | - 'required' => false, |
|
| 1483 | - 'validation' => true, |
|
| 1484 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1485 | - 'css_class' => '', |
|
| 1486 | - 'format' => '%d', |
|
| 1487 | - 'db-col' => 'MTP_is_override' |
|
| 1488 | - ); |
|
| 1477 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1478 | + 'name' => 'MTP_is_override', |
|
| 1479 | + 'label' => __('Override all custom', 'event_espresso'), |
|
| 1480 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1481 | + 'type' => 'int', |
|
| 1482 | + 'required' => false, |
|
| 1483 | + 'validation' => true, |
|
| 1484 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1485 | + 'css_class' => '', |
|
| 1486 | + 'format' => '%d', |
|
| 1487 | + 'db-col' => 'MTP_is_override' |
|
| 1488 | + ); |
|
| 1489 | 1489 | |
| 1490 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1491 | - 'name' => 'MTP_is_active', |
|
| 1492 | - 'label' => __('Active Template', 'event_espresso'), |
|
| 1493 | - 'input' => 'hidden', |
|
| 1494 | - 'type' => 'int', |
|
| 1495 | - 'required' => false, |
|
| 1496 | - 'validation' => true, |
|
| 1497 | - 'value' => $message_template_group->is_active(), |
|
| 1498 | - 'css_class' => '', |
|
| 1499 | - 'format' => '%d', |
|
| 1500 | - 'db-col' => 'MTP_is_active' |
|
| 1501 | - ); |
|
| 1490 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1491 | + 'name' => 'MTP_is_active', |
|
| 1492 | + 'label' => __('Active Template', 'event_espresso'), |
|
| 1493 | + 'input' => 'hidden', |
|
| 1494 | + 'type' => 'int', |
|
| 1495 | + 'required' => false, |
|
| 1496 | + 'validation' => true, |
|
| 1497 | + 'value' => $message_template_group->is_active(), |
|
| 1498 | + 'css_class' => '', |
|
| 1499 | + 'format' => '%d', |
|
| 1500 | + 'db-col' => 'MTP_is_active' |
|
| 1501 | + ); |
|
| 1502 | 1502 | |
| 1503 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1504 | - 'name' => 'MTP_deleted', |
|
| 1505 | - 'label' => null, |
|
| 1506 | - 'input' => 'hidden', |
|
| 1507 | - 'type' => 'int', |
|
| 1508 | - 'required' => false, |
|
| 1509 | - 'validation' => true, |
|
| 1510 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1511 | - 'css_class' => '', |
|
| 1512 | - 'format' => '%d', |
|
| 1513 | - 'db-col' => 'MTP_deleted' |
|
| 1514 | - ); |
|
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | - 'name' => 'MTP_user_id', |
|
| 1517 | - 'label' => __('Author', 'event_espresso'), |
|
| 1518 | - 'input' => 'hidden', |
|
| 1519 | - 'type' => 'int', |
|
| 1520 | - 'required' => false, |
|
| 1521 | - 'validation' => false, |
|
| 1522 | - 'value' => $message_template_group->user(), |
|
| 1523 | - 'format' => '%d', |
|
| 1524 | - 'db-col' => 'MTP_user_id' |
|
| 1525 | - ); |
|
| 1503 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1504 | + 'name' => 'MTP_deleted', |
|
| 1505 | + 'label' => null, |
|
| 1506 | + 'input' => 'hidden', |
|
| 1507 | + 'type' => 'int', |
|
| 1508 | + 'required' => false, |
|
| 1509 | + 'validation' => true, |
|
| 1510 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1511 | + 'css_class' => '', |
|
| 1512 | + 'format' => '%d', |
|
| 1513 | + 'db-col' => 'MTP_deleted' |
|
| 1514 | + ); |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | + 'name' => 'MTP_user_id', |
|
| 1517 | + 'label' => __('Author', 'event_espresso'), |
|
| 1518 | + 'input' => 'hidden', |
|
| 1519 | + 'type' => 'int', |
|
| 1520 | + 'required' => false, |
|
| 1521 | + 'validation' => false, |
|
| 1522 | + 'value' => $message_template_group->user(), |
|
| 1523 | + 'format' => '%d', |
|
| 1524 | + 'db-col' => 'MTP_user_id' |
|
| 1525 | + ); |
|
| 1526 | 1526 | |
| 1527 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1528 | - 'name' => 'action', |
|
| 1529 | - 'input' => 'hidden', |
|
| 1530 | - 'type' => 'string', |
|
| 1531 | - 'value' => $action |
|
| 1532 | - ); |
|
| 1527 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1528 | + 'name' => 'action', |
|
| 1529 | + 'input' => 'hidden', |
|
| 1530 | + 'type' => 'string', |
|
| 1531 | + 'value' => $action |
|
| 1532 | + ); |
|
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | - 'name' => 'id', |
|
| 1536 | - 'input' => 'hidden', |
|
| 1537 | - 'type' => 'int', |
|
| 1538 | - 'value' => $GRP_ID |
|
| 1539 | - ); |
|
| 1540 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1541 | - 'name' => $action . '_nonce', |
|
| 1542 | - 'input' => 'hidden', |
|
| 1543 | - 'type' => 'string', |
|
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1545 | - ); |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | + 'name' => 'id', |
|
| 1536 | + 'input' => 'hidden', |
|
| 1537 | + 'type' => 'int', |
|
| 1538 | + 'value' => $GRP_ID |
|
| 1539 | + ); |
|
| 1540 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1541 | + 'name' => $action . '_nonce', |
|
| 1542 | + 'input' => 'hidden', |
|
| 1543 | + 'type' => 'string', |
|
| 1544 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1545 | + ); |
|
| 1546 | 1546 | |
| 1547 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1548 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1549 | - 'name' => 'template_switch', |
|
| 1550 | - 'input' => 'hidden', |
|
| 1551 | - 'type' => 'int', |
|
| 1552 | - 'value' => 1 |
|
| 1553 | - ); |
|
| 1554 | - } |
|
| 1547 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1548 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1549 | + 'name' => 'template_switch', |
|
| 1550 | + 'input' => 'hidden', |
|
| 1551 | + 'type' => 'int', |
|
| 1552 | + 'value' => 1 |
|
| 1553 | + ); |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | 1556 | |
| 1557 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1558 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1557 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1558 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1559 | 1559 | |
| 1560 | 1560 | |
| 1561 | - } //end if ( !empty($template_field_structure) ) |
|
| 1561 | + } //end if ( !empty($template_field_structure) ) |
|
| 1562 | 1562 | |
| 1563 | - //set extra content for publish box |
|
| 1564 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1565 | - $this->_set_publish_post_box_vars( |
|
| 1566 | - 'id', |
|
| 1567 | - $GRP_ID, |
|
| 1568 | - false, |
|
| 1569 | - add_query_arg( |
|
| 1570 | - array('action' => 'global_mtps'), |
|
| 1571 | - $this->_admin_base_url |
|
| 1572 | - ) |
|
| 1573 | - ); |
|
| 1574 | - |
|
| 1575 | - //add preview button |
|
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | - array( |
|
| 1578 | - 'message_type' => $message_template_group->message_type(), |
|
| 1579 | - 'messenger' => $message_template_group->messenger(), |
|
| 1580 | - 'context' => $context, |
|
| 1581 | - 'GRP_ID' => $GRP_ID, |
|
| 1582 | - 'action' => 'preview_message' |
|
| 1583 | - ), |
|
| 1584 | - $this->_admin_base_url |
|
| 1585 | - ); |
|
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - //setup context switcher |
|
| 1591 | - $context_switcher_args = array( |
|
| 1592 | - 'page' => 'espresso_messages', |
|
| 1593 | - 'action' => 'edit_message_template', |
|
| 1594 | - 'id' => $GRP_ID, |
|
| 1595 | - 'context' => $context, |
|
| 1596 | - 'extra' => $preview_button |
|
| 1597 | - ); |
|
| 1598 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - //main box |
|
| 1602 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1603 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1604 | - $this->_template_args['action'] = $action; |
|
| 1605 | - $this->_template_args['context'] = $context; |
|
| 1606 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1607 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1611 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1612 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1613 | - |
|
| 1614 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1615 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | - |
|
| 1618 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1619 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1620 | - |
|
| 1621 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1622 | - $this->_template_args, true); |
|
| 1623 | - |
|
| 1624 | - |
|
| 1625 | - //finally, let's set the admin_page title |
|
| 1626 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1627 | - |
|
| 1628 | - |
|
| 1629 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1630 | - $this->_set_shortcodes(); |
|
| 1631 | - |
|
| 1632 | - |
|
| 1633 | - //final template wrapper |
|
| 1634 | - $this->display_admin_page_with_sidebar(); |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1639 | - { |
|
| 1640 | - return $mceInit; |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - public function add_context_switcher() |
|
| 1645 | - { |
|
| 1646 | - return $this->_context_switcher; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - public function _add_form_element_before() |
|
| 1650 | - { |
|
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - public function _add_form_element_after() |
|
| 1655 | - { |
|
| 1656 | - return '</form>'; |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * This executes switching the template pack for a message template. |
|
| 1662 | - * |
|
| 1663 | - * @since 4.5.0 |
|
| 1664 | - * |
|
| 1665 | - */ |
|
| 1666 | - public function switch_template_pack() |
|
| 1667 | - { |
|
| 1668 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1669 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1670 | - |
|
| 1671 | - //verify we have needed values. |
|
| 1672 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1673 | - $this->_template_args['error'] = true; |
|
| 1674 | - EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1675 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1676 | - } else { |
|
| 1677 | - //get template, set the new template_pack and then reset to default |
|
| 1678 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1679 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1563 | + //set extra content for publish box |
|
| 1564 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1565 | + $this->_set_publish_post_box_vars( |
|
| 1566 | + 'id', |
|
| 1567 | + $GRP_ID, |
|
| 1568 | + false, |
|
| 1569 | + add_query_arg( |
|
| 1570 | + array('action' => 'global_mtps'), |
|
| 1571 | + $this->_admin_base_url |
|
| 1572 | + ) |
|
| 1573 | + ); |
|
| 1574 | + |
|
| 1575 | + //add preview button |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | + array( |
|
| 1578 | + 'message_type' => $message_template_group->message_type(), |
|
| 1579 | + 'messenger' => $message_template_group->messenger(), |
|
| 1580 | + 'context' => $context, |
|
| 1581 | + 'GRP_ID' => $GRP_ID, |
|
| 1582 | + 'action' => 'preview_message' |
|
| 1583 | + ), |
|
| 1584 | + $this->_admin_base_url |
|
| 1585 | + ); |
|
| 1586 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | + 'event_espresso') . '</a>'; |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + //setup context switcher |
|
| 1591 | + $context_switcher_args = array( |
|
| 1592 | + 'page' => 'espresso_messages', |
|
| 1593 | + 'action' => 'edit_message_template', |
|
| 1594 | + 'id' => $GRP_ID, |
|
| 1595 | + 'context' => $context, |
|
| 1596 | + 'extra' => $preview_button |
|
| 1597 | + ); |
|
| 1598 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + //main box |
|
| 1602 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1603 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1604 | + $this->_template_args['action'] = $action; |
|
| 1605 | + $this->_template_args['context'] = $context; |
|
| 1606 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1607 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1611 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1612 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1613 | + |
|
| 1614 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1615 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | + |
|
| 1618 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1619 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1620 | + |
|
| 1621 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1622 | + $this->_template_args, true); |
|
| 1623 | + |
|
| 1624 | + |
|
| 1625 | + //finally, let's set the admin_page title |
|
| 1626 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1627 | + |
|
| 1628 | + |
|
| 1629 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1630 | + $this->_set_shortcodes(); |
|
| 1631 | + |
|
| 1632 | + |
|
| 1633 | + //final template wrapper |
|
| 1634 | + $this->display_admin_page_with_sidebar(); |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1639 | + { |
|
| 1640 | + return $mceInit; |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + public function add_context_switcher() |
|
| 1645 | + { |
|
| 1646 | + return $this->_context_switcher; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + public function _add_form_element_before() |
|
| 1650 | + { |
|
| 1651 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + public function _add_form_element_after() |
|
| 1655 | + { |
|
| 1656 | + return '</form>'; |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * This executes switching the template pack for a message template. |
|
| 1662 | + * |
|
| 1663 | + * @since 4.5.0 |
|
| 1664 | + * |
|
| 1665 | + */ |
|
| 1666 | + public function switch_template_pack() |
|
| 1667 | + { |
|
| 1668 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1669 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1670 | + |
|
| 1671 | + //verify we have needed values. |
|
| 1672 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1673 | + $this->_template_args['error'] = true; |
|
| 1674 | + EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1675 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1676 | + } else { |
|
| 1677 | + //get template, set the new template_pack and then reset to default |
|
| 1678 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1679 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1680 | 1680 | |
| 1681 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1682 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1683 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1681 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1682 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1683 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1684 | 1684 | |
| 1685 | - $query_args = $this->_reset_to_default_template(); |
|
| 1685 | + $query_args = $this->_reset_to_default_template(); |
|
| 1686 | 1686 | |
| 1687 | - if (empty($query_args['id'])) { |
|
| 1688 | - EE_Error::add_error( |
|
| 1689 | - __( |
|
| 1690 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1691 | - 'event_espresso' |
|
| 1692 | - ), |
|
| 1693 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1694 | - ); |
|
| 1695 | - $this->_template_args['error'] = true; |
|
| 1696 | - } else { |
|
| 1697 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1698 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1699 | - EE_Error::add_success( |
|
| 1700 | - sprintf( |
|
| 1701 | - __( |
|
| 1702 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1703 | - 'event_espresso' |
|
| 1704 | - ), |
|
| 1705 | - $template_label, |
|
| 1706 | - $template_pack_labels->template_pack |
|
| 1707 | - ) |
|
| 1708 | - ); |
|
| 1709 | - //generate the redirect url for js. |
|
| 1710 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1711 | - $this->_admin_base_url); |
|
| 1712 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1713 | - $this->_template_args['success'] = true; |
|
| 1714 | - } |
|
| 1687 | + if (empty($query_args['id'])) { |
|
| 1688 | + EE_Error::add_error( |
|
| 1689 | + __( |
|
| 1690 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1691 | + 'event_espresso' |
|
| 1692 | + ), |
|
| 1693 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1694 | + ); |
|
| 1695 | + $this->_template_args['error'] = true; |
|
| 1696 | + } else { |
|
| 1697 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1698 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1699 | + EE_Error::add_success( |
|
| 1700 | + sprintf( |
|
| 1701 | + __( |
|
| 1702 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1703 | + 'event_espresso' |
|
| 1704 | + ), |
|
| 1705 | + $template_label, |
|
| 1706 | + $template_pack_labels->template_pack |
|
| 1707 | + ) |
|
| 1708 | + ); |
|
| 1709 | + //generate the redirect url for js. |
|
| 1710 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1711 | + $this->_admin_base_url); |
|
| 1712 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1713 | + $this->_template_args['success'] = true; |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - $this->_return_json(); |
|
| 1716 | + $this->_return_json(); |
|
| 1717 | 1717 | |
| 1718 | - } |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1724 | - * they want. |
|
| 1725 | - * |
|
| 1726 | - * @access protected |
|
| 1727 | - * @return array|null |
|
| 1728 | - */ |
|
| 1729 | - protected function _reset_to_default_template() |
|
| 1730 | - { |
|
| 1731 | - |
|
| 1732 | - $templates = array(); |
|
| 1733 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1734 | - //we need to make sure we've got the info we need. |
|
| 1735 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1736 | - EE_Error::add_error( |
|
| 1737 | - __( |
|
| 1738 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1739 | - 'event_espresso' |
|
| 1740 | - ), |
|
| 1741 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1742 | - ); |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // all templates will be reset to whatever the defaults are |
|
| 1746 | - // for the global template matching the messenger and message type. |
|
| 1747 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 1748 | - |
|
| 1749 | - if ($success) { |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1724 | + * they want. |
|
| 1725 | + * |
|
| 1726 | + * @access protected |
|
| 1727 | + * @return array|null |
|
| 1728 | + */ |
|
| 1729 | + protected function _reset_to_default_template() |
|
| 1730 | + { |
|
| 1731 | + |
|
| 1732 | + $templates = array(); |
|
| 1733 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1734 | + //we need to make sure we've got the info we need. |
|
| 1735 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1736 | + EE_Error::add_error( |
|
| 1737 | + __( |
|
| 1738 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1739 | + 'event_espresso' |
|
| 1740 | + ), |
|
| 1741 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1742 | + ); |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // all templates will be reset to whatever the defaults are |
|
| 1746 | + // for the global template matching the messenger and message type. |
|
| 1747 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 1748 | + |
|
| 1749 | + if ($success) { |
|
| 1750 | 1750 | |
| 1751 | - //let's first determine if the incoming template is a global template, |
|
| 1752 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1753 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1751 | + //let's first determine if the incoming template is a global template, |
|
| 1752 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1753 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1754 | 1754 | |
| 1755 | 1755 | |
| 1756 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1757 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1756 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1757 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1758 | 1758 | |
| 1759 | - if ($success) { |
|
| 1760 | - // if successfully deleted, lets generate the new ones. |
|
| 1761 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1762 | - // will use the related global template defaults for regeneration. |
|
| 1763 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1764 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 1765 | - // for the current custom template when resetting. |
|
| 1766 | - $templates = $this->_generate_new_templates( |
|
| 1767 | - $this->_req_data['msgr'], |
|
| 1768 | - $this->_req_data['mt'], |
|
| 1769 | - $GRP_ID, |
|
| 1770 | - true |
|
| 1771 | - ); |
|
| 1772 | - } |
|
| 1759 | + if ($success) { |
|
| 1760 | + // if successfully deleted, lets generate the new ones. |
|
| 1761 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1762 | + // will use the related global template defaults for regeneration. |
|
| 1763 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1764 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 1765 | + // for the current custom template when resetting. |
|
| 1766 | + $templates = $this->_generate_new_templates( |
|
| 1767 | + $this->_req_data['msgr'], |
|
| 1768 | + $this->_req_data['mt'], |
|
| 1769 | + $GRP_ID, |
|
| 1770 | + true |
|
| 1771 | + ); |
|
| 1772 | + } |
|
| 1773 | 1773 | |
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - //any error messages? |
|
| 1777 | - if ( ! $success) { |
|
| 1778 | - EE_Error::add_error( |
|
| 1779 | - __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1780 | - 'event_espresso'), |
|
| 1781 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1782 | - ); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - //all good, let's add a success message! |
|
| 1786 | - if ($success && ! empty($templates)) { |
|
| 1787 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1788 | - EE_Error::overwrite_success(); |
|
| 1789 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - |
|
| 1793 | - $query_args = array( |
|
| 1794 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1795 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1796 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1797 | - ); |
|
| 1798 | - |
|
| 1799 | - //if called via ajax then we return query args otherwise redirect |
|
| 1800 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1801 | - return $query_args; |
|
| 1802 | - } else { |
|
| 1803 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + //any error messages? |
|
| 1777 | + if ( ! $success) { |
|
| 1778 | + EE_Error::add_error( |
|
| 1779 | + __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1780 | + 'event_espresso'), |
|
| 1781 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1782 | + ); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + //all good, let's add a success message! |
|
| 1786 | + if ($success && ! empty($templates)) { |
|
| 1787 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1788 | + EE_Error::overwrite_success(); |
|
| 1789 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + |
|
| 1793 | + $query_args = array( |
|
| 1794 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1795 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1796 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1797 | + ); |
|
| 1798 | + |
|
| 1799 | + //if called via ajax then we return query args otherwise redirect |
|
| 1800 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1801 | + return $query_args; |
|
| 1802 | + } else { |
|
| 1803 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1804 | 1804 | |
| 1805 | - return null; |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * Retrieve and set the message preview for display. |
|
| 1812 | - * |
|
| 1813 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1814 | - * |
|
| 1815 | - * @return string |
|
| 1816 | - */ |
|
| 1817 | - public function _preview_message($send = false) |
|
| 1818 | - { |
|
| 1819 | - //first make sure we've got the necessary parameters |
|
| 1820 | - if ( |
|
| 1821 | - ! isset( |
|
| 1822 | - $this->_req_data['message_type'], |
|
| 1823 | - $this->_req_data['messenger'], |
|
| 1824 | - $this->_req_data['messenger'], |
|
| 1825 | - $this->_req_data['GRP_ID'] |
|
| 1826 | - ) |
|
| 1827 | - ) { |
|
| 1828 | - EE_Error::add_error( |
|
| 1829 | - __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1830 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1831 | - ); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1835 | - |
|
| 1836 | - |
|
| 1837 | - //get the preview! |
|
| 1838 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1839 | - $this->_req_data['messenger'], $send); |
|
| 1840 | - |
|
| 1841 | - if ($send) { |
|
| 1842 | - return $preview; |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - //let's add a button to go back to the edit view |
|
| 1846 | - $query_args = array( |
|
| 1847 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 1848 | - 'context' => $this->_req_data['context'], |
|
| 1849 | - 'action' => 'edit_message_template' |
|
| 1850 | - ); |
|
| 1851 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1854 | - $message_types = $this->get_installed_message_types(); |
|
| 1855 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1856 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1857 | - ? ucwords($active_messenger->label['singular']) |
|
| 1858 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1859 | - //let's provide a helpful title for context |
|
| 1860 | - $preview_title = sprintf( |
|
| 1861 | - __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1862 | - $active_messenger_label, |
|
| 1863 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1864 | - ); |
|
| 1865 | - //setup display of preview. |
|
| 1866 | - $this->_admin_page_title = $preview_title; |
|
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1868 | - $this->_template_args['data']['force_json'] = true; |
|
| 1869 | - |
|
| 1870 | - return ''; |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1876 | - * gets called automatically. |
|
| 1877 | - * |
|
| 1878 | - * @since 4.5.0 |
|
| 1879 | - * |
|
| 1880 | - * @return string |
|
| 1881 | - */ |
|
| 1882 | - protected function _display_preview_message() |
|
| 1883 | - { |
|
| 1884 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1885 | - } |
|
| 1886 | - |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1890 | - * |
|
| 1891 | - * @access protected |
|
| 1892 | - * @return void |
|
| 1893 | - */ |
|
| 1894 | - protected function _register_edit_meta_boxes() |
|
| 1895 | - { |
|
| 1896 | - add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1897 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1898 | - add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1899 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1900 | - add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1901 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * metabox content for all template pack and variation selection. |
|
| 1907 | - * |
|
| 1908 | - * @since 4.5.0 |
|
| 1909 | - * |
|
| 1910 | - * @return string |
|
| 1911 | - */ |
|
| 1912 | - public function template_pack_meta_box() |
|
| 1913 | - { |
|
| 1914 | - $this->_set_message_template_group(); |
|
| 1915 | - |
|
| 1916 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1917 | - |
|
| 1918 | - $tp_select_values = array(); |
|
| 1919 | - |
|
| 1920 | - foreach ($tp_collection as $tp) { |
|
| 1921 | - //only include template packs that support this messenger and message type! |
|
| 1922 | - $supports = $tp->get_supports(); |
|
| 1923 | - if ( |
|
| 1924 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1925 | - || ! in_array( |
|
| 1926 | - $this->_message_template_group->message_type(), |
|
| 1927 | - $supports[$this->_message_template_group->messenger()] |
|
| 1928 | - ) |
|
| 1929 | - ) { |
|
| 1930 | - //not supported |
|
| 1931 | - continue; |
|
| 1932 | - } |
|
| 1805 | + return null; |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * Retrieve and set the message preview for display. |
|
| 1812 | + * |
|
| 1813 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1814 | + * |
|
| 1815 | + * @return string |
|
| 1816 | + */ |
|
| 1817 | + public function _preview_message($send = false) |
|
| 1818 | + { |
|
| 1819 | + //first make sure we've got the necessary parameters |
|
| 1820 | + if ( |
|
| 1821 | + ! isset( |
|
| 1822 | + $this->_req_data['message_type'], |
|
| 1823 | + $this->_req_data['messenger'], |
|
| 1824 | + $this->_req_data['messenger'], |
|
| 1825 | + $this->_req_data['GRP_ID'] |
|
| 1826 | + ) |
|
| 1827 | + ) { |
|
| 1828 | + EE_Error::add_error( |
|
| 1829 | + __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1830 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1831 | + ); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1835 | + |
|
| 1836 | + |
|
| 1837 | + //get the preview! |
|
| 1838 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1839 | + $this->_req_data['messenger'], $send); |
|
| 1840 | + |
|
| 1841 | + if ($send) { |
|
| 1842 | + return $preview; |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + //let's add a button to go back to the edit view |
|
| 1846 | + $query_args = array( |
|
| 1847 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 1848 | + 'context' => $this->_req_data['context'], |
|
| 1849 | + 'action' => 'edit_message_template' |
|
| 1850 | + ); |
|
| 1851 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1852 | + $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | + 'event_espresso') . '</a>'; |
|
| 1854 | + $message_types = $this->get_installed_message_types(); |
|
| 1855 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1856 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1857 | + ? ucwords($active_messenger->label['singular']) |
|
| 1858 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1859 | + //let's provide a helpful title for context |
|
| 1860 | + $preview_title = sprintf( |
|
| 1861 | + __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1862 | + $active_messenger_label, |
|
| 1863 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1864 | + ); |
|
| 1865 | + //setup display of preview. |
|
| 1866 | + $this->_admin_page_title = $preview_title; |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1868 | + $this->_template_args['data']['force_json'] = true; |
|
| 1869 | + |
|
| 1870 | + return ''; |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1876 | + * gets called automatically. |
|
| 1877 | + * |
|
| 1878 | + * @since 4.5.0 |
|
| 1879 | + * |
|
| 1880 | + * @return string |
|
| 1881 | + */ |
|
| 1882 | + protected function _display_preview_message() |
|
| 1883 | + { |
|
| 1884 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1885 | + } |
|
| 1886 | + |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1890 | + * |
|
| 1891 | + * @access protected |
|
| 1892 | + * @return void |
|
| 1893 | + */ |
|
| 1894 | + protected function _register_edit_meta_boxes() |
|
| 1895 | + { |
|
| 1896 | + add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1897 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1898 | + add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1899 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1900 | + add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1901 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * metabox content for all template pack and variation selection. |
|
| 1907 | + * |
|
| 1908 | + * @since 4.5.0 |
|
| 1909 | + * |
|
| 1910 | + * @return string |
|
| 1911 | + */ |
|
| 1912 | + public function template_pack_meta_box() |
|
| 1913 | + { |
|
| 1914 | + $this->_set_message_template_group(); |
|
| 1915 | + |
|
| 1916 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1917 | + |
|
| 1918 | + $tp_select_values = array(); |
|
| 1919 | + |
|
| 1920 | + foreach ($tp_collection as $tp) { |
|
| 1921 | + //only include template packs that support this messenger and message type! |
|
| 1922 | + $supports = $tp->get_supports(); |
|
| 1923 | + if ( |
|
| 1924 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1925 | + || ! in_array( |
|
| 1926 | + $this->_message_template_group->message_type(), |
|
| 1927 | + $supports[$this->_message_template_group->messenger()] |
|
| 1928 | + ) |
|
| 1929 | + ) { |
|
| 1930 | + //not supported |
|
| 1931 | + continue; |
|
| 1932 | + } |
|
| 1933 | 1933 | |
| 1934 | - $tp_select_values[] = array( |
|
| 1935 | - 'text' => $tp->label, |
|
| 1936 | - 'id' => $tp->dbref |
|
| 1937 | - ); |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1941 | - if (empty($tp_select_values)) { |
|
| 1942 | - $tp_select_values[] = array( |
|
| 1943 | - 'text' => __('Default', 'event_espresso'), |
|
| 1944 | - 'id' => 'default' |
|
| 1945 | - ); |
|
| 1946 | - } |
|
| 1947 | - |
|
| 1948 | - //setup variation select values for the currently selected template. |
|
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | - $this->_message_template_group->messenger(), |
|
| 1951 | - $this->_message_template_group->message_type() |
|
| 1952 | - ); |
|
| 1953 | - $variations_select_values = array(); |
|
| 1954 | - foreach ($variations as $variation => $label) { |
|
| 1955 | - $variations_select_values[] = array( |
|
| 1956 | - 'text' => $label, |
|
| 1957 | - 'id' => $variation |
|
| 1958 | - ); |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1962 | - |
|
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | - 'MTP_template_pack', |
|
| 1965 | - $tp_select_values, |
|
| 1966 | - $this->_message_template_group->get_template_pack_name() |
|
| 1967 | - ); |
|
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | - 'MTP_template_variation', |
|
| 1970 | - $variations_select_values, |
|
| 1971 | - $this->_message_template_group->get_template_pack_variation() |
|
| 1972 | - ); |
|
| 1973 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1974 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1975 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1976 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1977 | - |
|
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | - |
|
| 1980 | - EEH_Template::display_template($template, $template_args); |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * This meta box holds any extra actions related to Message Templates |
|
| 1986 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1987 | - * |
|
| 1988 | - * @access public |
|
| 1989 | - * @return void |
|
| 1990 | - * @throws \EE_Error |
|
| 1991 | - */ |
|
| 1992 | - public function extra_actions_meta_box() |
|
| 1993 | - { |
|
| 1994 | - $template_form_fields = array(); |
|
| 1995 | - |
|
| 1996 | - $extra_args = array( |
|
| 1997 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 1998 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 1999 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2000 | - ); |
|
| 2001 | - //first we need to see if there are any fields |
|
| 2002 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2003 | - |
|
| 2004 | - if ( ! empty($fields)) { |
|
| 2005 | - //yup there be fields |
|
| 2006 | - foreach ($fields as $field => $config) { |
|
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2008 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2009 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2010 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 1934 | + $tp_select_values[] = array( |
|
| 1935 | + 'text' => $tp->label, |
|
| 1936 | + 'id' => $tp->dbref |
|
| 1937 | + ); |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1941 | + if (empty($tp_select_values)) { |
|
| 1942 | + $tp_select_values[] = array( |
|
| 1943 | + 'text' => __('Default', 'event_espresso'), |
|
| 1944 | + 'id' => 'default' |
|
| 1945 | + ); |
|
| 1946 | + } |
|
| 1947 | + |
|
| 1948 | + //setup variation select values for the currently selected template. |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | + $this->_message_template_group->messenger(), |
|
| 1951 | + $this->_message_template_group->message_type() |
|
| 1952 | + ); |
|
| 1953 | + $variations_select_values = array(); |
|
| 1954 | + foreach ($variations as $variation => $label) { |
|
| 1955 | + $variations_select_values[] = array( |
|
| 1956 | + 'text' => $label, |
|
| 1957 | + 'id' => $variation |
|
| 1958 | + ); |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1962 | + |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | + 'MTP_template_pack', |
|
| 1965 | + $tp_select_values, |
|
| 1966 | + $this->_message_template_group->get_template_pack_name() |
|
| 1967 | + ); |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | + 'MTP_template_variation', |
|
| 1970 | + $variations_select_values, |
|
| 1971 | + $this->_message_template_group->get_template_pack_variation() |
|
| 1972 | + ); |
|
| 1973 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1974 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1975 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1976 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1977 | + |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | + |
|
| 1980 | + EEH_Template::display_template($template, $template_args); |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * This meta box holds any extra actions related to Message Templates |
|
| 1986 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1987 | + * |
|
| 1988 | + * @access public |
|
| 1989 | + * @return void |
|
| 1990 | + * @throws \EE_Error |
|
| 1991 | + */ |
|
| 1992 | + public function extra_actions_meta_box() |
|
| 1993 | + { |
|
| 1994 | + $template_form_fields = array(); |
|
| 1995 | + |
|
| 1996 | + $extra_args = array( |
|
| 1997 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 1998 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 1999 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2000 | + ); |
|
| 2001 | + //first we need to see if there are any fields |
|
| 2002 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2003 | + |
|
| 2004 | + if ( ! empty($fields)) { |
|
| 2005 | + //yup there be fields |
|
| 2006 | + foreach ($fields as $field => $config) { |
|
| 2007 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2008 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2009 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2010 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2011 | 2011 | |
| 2012 | - // if type is hidden and the value is empty |
|
| 2013 | - // something may have gone wrong so let's correct with the defaults |
|
| 2014 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2015 | - ? $default |
|
| 2016 | - : ''; |
|
| 2017 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2018 | - ? $existing[$field] |
|
| 2019 | - : $fix; |
|
| 2012 | + // if type is hidden and the value is empty |
|
| 2013 | + // something may have gone wrong so let's correct with the defaults |
|
| 2014 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2015 | + ? $default |
|
| 2016 | + : ''; |
|
| 2017 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2018 | + ? $existing[$field] |
|
| 2019 | + : $fix; |
|
| 2020 | 2020 | |
| 2021 | - $template_form_fields[$field_id] = array( |
|
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2023 | - 'label' => $config['label'], |
|
| 2024 | - 'input' => $config['input'], |
|
| 2025 | - 'type' => $config['type'], |
|
| 2026 | - 'required' => $config['required'], |
|
| 2027 | - 'validation' => $config['validation'], |
|
| 2028 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2029 | - 'css_class' => $config['css_class'], |
|
| 2030 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2031 | - 'default' => $default, |
|
| 2032 | - 'format' => $config['format'] |
|
| 2033 | - ); |
|
| 2034 | - } |
|
| 2035 | - } |
|
| 2036 | - |
|
| 2037 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2038 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2039 | - : ''; |
|
| 2040 | - |
|
| 2041 | - $test_settings_html = ''; |
|
| 2042 | - //print out $test_settings_fields |
|
| 2043 | - if ( ! empty($test_settings_fields)) { |
|
| 2044 | - echo $test_settings_fields; |
|
| 2045 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2046 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2047 | - $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2048 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2049 | - } |
|
| 2050 | - |
|
| 2051 | - //and button |
|
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2053 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2054 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2055 | - 'reset_to_default', |
|
| 2056 | - 'reset', |
|
| 2057 | - $extra_args, |
|
| 2058 | - 'button-primary reset-default-button' |
|
| 2059 | - ); |
|
| 2060 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2061 | - echo $test_settings_html; |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2067 | - * |
|
| 2068 | - * @since 4.9.rc.000 |
|
| 2069 | - * |
|
| 2070 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2071 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2072 | - * |
|
| 2073 | - * @return string |
|
| 2074 | - */ |
|
| 2075 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2076 | - { |
|
| 2077 | - $template_args = array( |
|
| 2078 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2079 | - 'fieldname' => $field, |
|
| 2080 | - 'linked_input_id' => $linked_input_id |
|
| 2081 | - ); |
|
| 2082 | - |
|
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2084 | - $template_args, true); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2090 | - * page) |
|
| 2091 | - * |
|
| 2092 | - * @access public |
|
| 2093 | - * @return void |
|
| 2094 | - */ |
|
| 2095 | - public function shortcode_meta_box() |
|
| 2096 | - { |
|
| 2097 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2098 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2099 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2100 | - if (empty($shortcodes)) { |
|
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2102 | - echo $content; |
|
| 2103 | - } else { |
|
| 2104 | - //$alt = 0; |
|
| 2105 | - ?> |
|
| 2021 | + $template_form_fields[$field_id] = array( |
|
| 2022 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2023 | + 'label' => $config['label'], |
|
| 2024 | + 'input' => $config['input'], |
|
| 2025 | + 'type' => $config['type'], |
|
| 2026 | + 'required' => $config['required'], |
|
| 2027 | + 'validation' => $config['validation'], |
|
| 2028 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2029 | + 'css_class' => $config['css_class'], |
|
| 2030 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2031 | + 'default' => $default, |
|
| 2032 | + 'format' => $config['format'] |
|
| 2033 | + ); |
|
| 2034 | + } |
|
| 2035 | + } |
|
| 2036 | + |
|
| 2037 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2038 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2039 | + : ''; |
|
| 2040 | + |
|
| 2041 | + $test_settings_html = ''; |
|
| 2042 | + //print out $test_settings_fields |
|
| 2043 | + if ( ! empty($test_settings_fields)) { |
|
| 2044 | + echo $test_settings_fields; |
|
| 2045 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2046 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2047 | + $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2048 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2049 | + } |
|
| 2050 | + |
|
| 2051 | + //and button |
|
| 2052 | + $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2053 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2054 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2055 | + 'reset_to_default', |
|
| 2056 | + 'reset', |
|
| 2057 | + $extra_args, |
|
| 2058 | + 'button-primary reset-default-button' |
|
| 2059 | + ); |
|
| 2060 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2061 | + echo $test_settings_html; |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2067 | + * |
|
| 2068 | + * @since 4.9.rc.000 |
|
| 2069 | + * |
|
| 2070 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2071 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2072 | + * |
|
| 2073 | + * @return string |
|
| 2074 | + */ |
|
| 2075 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2076 | + { |
|
| 2077 | + $template_args = array( |
|
| 2078 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2079 | + 'fieldname' => $field, |
|
| 2080 | + 'linked_input_id' => $linked_input_id |
|
| 2081 | + ); |
|
| 2082 | + |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2084 | + $template_args, true); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2090 | + * page) |
|
| 2091 | + * |
|
| 2092 | + * @access public |
|
| 2093 | + * @return void |
|
| 2094 | + */ |
|
| 2095 | + public function shortcode_meta_box() |
|
| 2096 | + { |
|
| 2097 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2098 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2099 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2100 | + if (empty($shortcodes)) { |
|
| 2101 | + $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2102 | + echo $content; |
|
| 2103 | + } else { |
|
| 2104 | + //$alt = 0; |
|
| 2105 | + ?> |
|
| 2106 | 2106 | <div |
| 2107 | 2107 | style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2108 | 2108 | <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
| 2109 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2109 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2110 | 2110 | <?php |
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - |
|
| 2117 | - /** |
|
| 2118 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2119 | - * |
|
| 2120 | - * @access protected |
|
| 2121 | - * @return void |
|
| 2122 | - */ |
|
| 2123 | - protected function _set_shortcodes() |
|
| 2124 | - { |
|
| 2125 | - |
|
| 2126 | - //no need to run this if the property is already set |
|
| 2127 | - if ( ! empty($this->_shortcodes)) { |
|
| 2128 | - return; |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2132 | - } |
|
| 2133 | - |
|
| 2134 | - |
|
| 2135 | - /** |
|
| 2136 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2137 | - * property) |
|
| 2138 | - * |
|
| 2139 | - * @access protected |
|
| 2140 | - * |
|
| 2141 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2142 | - * for. Defaults to all (for the given context) |
|
| 2143 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2144 | - * |
|
| 2145 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2146 | - * true just an array of shortcode/label pairs. |
|
| 2147 | - */ |
|
| 2148 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2149 | - { |
|
| 2150 | - $this->_set_message_template_group(); |
|
| 2151 | - |
|
| 2152 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2153 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2154 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2155 | - |
|
| 2156 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - |
|
| 2160 | - /** |
|
| 2161 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2162 | - * |
|
| 2163 | - * @access protected |
|
| 2164 | - * @return void |
|
| 2165 | - */ |
|
| 2166 | - protected function _set_message_template_group() |
|
| 2167 | - { |
|
| 2168 | - |
|
| 2169 | - if ( ! empty($this->_message_template_group)) { |
|
| 2170 | - return; |
|
| 2171 | - } //get out if this is already set. |
|
| 2172 | - |
|
| 2173 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2174 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2175 | - |
|
| 2176 | - //let's get the message templates |
|
| 2177 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2178 | - |
|
| 2179 | - if (empty($GRP_ID)) { |
|
| 2180 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2181 | - } else { |
|
| 2182 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2186 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2187 | - |
|
| 2188 | - } |
|
| 2189 | - |
|
| 2190 | - |
|
| 2191 | - /** |
|
| 2192 | - * sets up a context switcher for edit forms |
|
| 2193 | - * |
|
| 2194 | - * @access protected |
|
| 2195 | - * |
|
| 2196 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2197 | - * @param array $args various things the context switcher needs. |
|
| 2198 | - * |
|
| 2199 | - */ |
|
| 2200 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2201 | - { |
|
| 2202 | - $context_details = $template_group_object->contexts_config(); |
|
| 2203 | - $context_label = $template_group_object->context_label(); |
|
| 2204 | - ob_start(); |
|
| 2205 | - ?> |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + |
|
| 2117 | + /** |
|
| 2118 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2119 | + * |
|
| 2120 | + * @access protected |
|
| 2121 | + * @return void |
|
| 2122 | + */ |
|
| 2123 | + protected function _set_shortcodes() |
|
| 2124 | + { |
|
| 2125 | + |
|
| 2126 | + //no need to run this if the property is already set |
|
| 2127 | + if ( ! empty($this->_shortcodes)) { |
|
| 2128 | + return; |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2132 | + } |
|
| 2133 | + |
|
| 2134 | + |
|
| 2135 | + /** |
|
| 2136 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2137 | + * property) |
|
| 2138 | + * |
|
| 2139 | + * @access protected |
|
| 2140 | + * |
|
| 2141 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2142 | + * for. Defaults to all (for the given context) |
|
| 2143 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2144 | + * |
|
| 2145 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2146 | + * true just an array of shortcode/label pairs. |
|
| 2147 | + */ |
|
| 2148 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2149 | + { |
|
| 2150 | + $this->_set_message_template_group(); |
|
| 2151 | + |
|
| 2152 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2153 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2154 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2155 | + |
|
| 2156 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + |
|
| 2160 | + /** |
|
| 2161 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2162 | + * |
|
| 2163 | + * @access protected |
|
| 2164 | + * @return void |
|
| 2165 | + */ |
|
| 2166 | + protected function _set_message_template_group() |
|
| 2167 | + { |
|
| 2168 | + |
|
| 2169 | + if ( ! empty($this->_message_template_group)) { |
|
| 2170 | + return; |
|
| 2171 | + } //get out if this is already set. |
|
| 2172 | + |
|
| 2173 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2174 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2175 | + |
|
| 2176 | + //let's get the message templates |
|
| 2177 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2178 | + |
|
| 2179 | + if (empty($GRP_ID)) { |
|
| 2180 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2181 | + } else { |
|
| 2182 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2186 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2187 | + |
|
| 2188 | + } |
|
| 2189 | + |
|
| 2190 | + |
|
| 2191 | + /** |
|
| 2192 | + * sets up a context switcher for edit forms |
|
| 2193 | + * |
|
| 2194 | + * @access protected |
|
| 2195 | + * |
|
| 2196 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2197 | + * @param array $args various things the context switcher needs. |
|
| 2198 | + * |
|
| 2199 | + */ |
|
| 2200 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2201 | + { |
|
| 2202 | + $context_details = $template_group_object->contexts_config(); |
|
| 2203 | + $context_label = $template_group_object->context_label(); |
|
| 2204 | + ob_start(); |
|
| 2205 | + ?> |
|
| 2206 | 2206 | <div class="ee-msg-switcher-container"> |
| 2207 | 2207 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2208 | 2208 | <?php |
| 2209 | - foreach ($args as $name => $value) { |
|
| 2210 | - if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2211 | - continue; |
|
| 2212 | - } |
|
| 2213 | - ?> |
|
| 2209 | + foreach ($args as $name => $value) { |
|
| 2210 | + if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2211 | + continue; |
|
| 2212 | + } |
|
| 2213 | + ?> |
|
| 2214 | 2214 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2215 | 2215 | <?php |
| 2216 | - } |
|
| 2217 | - //setup nonce_url |
|
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2219 | - ?> |
|
| 2216 | + } |
|
| 2217 | + //setup nonce_url |
|
| 2218 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2219 | + ?> |
|
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
| 2222 | - $context_templates = $template_group_object->context_templates(); |
|
| 2223 | - if (is_array($context_templates)) : |
|
| 2224 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2225 | - $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2226 | - ?> |
|
| 2222 | + $context_templates = $template_group_object->context_templates(); |
|
| 2223 | + if (is_array($context_templates)) : |
|
| 2224 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2225 | + $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2226 | + ?> |
|
| 2227 | 2227 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2228 | 2228 | <?php echo $context_details[$context]['label']; ?> |
| 2229 | 2229 | </option> |
@@ -2236,1554 +2236,1554 @@ discard block |
||
| 2236 | 2236 | <?php echo $args['extra']; ?> |
| 2237 | 2237 | </div> <!-- end .ee-msg-switcher-container --> |
| 2238 | 2238 | <?php |
| 2239 | - $output = ob_get_contents(); |
|
| 2240 | - ob_clean(); |
|
| 2241 | - $this->_context_switcher = $output; |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * utility for sanitizing new values coming in. |
|
| 2247 | - * Note: this is only used when updating a context. |
|
| 2248 | - * |
|
| 2249 | - * @access protected |
|
| 2250 | - * |
|
| 2251 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2252 | - * |
|
| 2253 | - * @return array |
|
| 2254 | - */ |
|
| 2255 | - protected function _set_message_template_column_values($index) |
|
| 2256 | - { |
|
| 2257 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2258 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2259 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2260 | - } |
|
| 2261 | - } /*else { |
|
| 2239 | + $output = ob_get_contents(); |
|
| 2240 | + ob_clean(); |
|
| 2241 | + $this->_context_switcher = $output; |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * utility for sanitizing new values coming in. |
|
| 2247 | + * Note: this is only used when updating a context. |
|
| 2248 | + * |
|
| 2249 | + * @access protected |
|
| 2250 | + * |
|
| 2251 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2252 | + * |
|
| 2253 | + * @return array |
|
| 2254 | + */ |
|
| 2255 | + protected function _set_message_template_column_values($index) |
|
| 2256 | + { |
|
| 2257 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2258 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2259 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2260 | + } |
|
| 2261 | + } /*else { |
|
| 2262 | 2262 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
| 2263 | 2263 | }*/ |
| 2264 | 2264 | |
| 2265 | 2265 | |
| 2266 | - $set_column_values = array( |
|
| 2267 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2268 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2269 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2270 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2271 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2272 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2273 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2274 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2275 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2276 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2277 | - : 0, |
|
| 2278 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2279 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2280 | - : 0, |
|
| 2281 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2282 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2283 | - ); |
|
| 2284 | - |
|
| 2285 | - |
|
| 2286 | - return $set_column_values; |
|
| 2287 | - } |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - protected function _insert_or_update_message_template($new = false) |
|
| 2291 | - { |
|
| 2292 | - |
|
| 2293 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2294 | - $success = 0; |
|
| 2295 | - $override = false; |
|
| 2296 | - |
|
| 2297 | - //setup notices description |
|
| 2298 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2299 | - |
|
| 2300 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2301 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2302 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2303 | - |
|
| 2304 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2305 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2306 | - |
|
| 2307 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2308 | - ? ucwords($message_type_object->label['singular']) |
|
| 2309 | - : ''; |
|
| 2310 | - |
|
| 2311 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2312 | - ? $this->_req_data['MTP_context'] |
|
| 2313 | - : ''; |
|
| 2314 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2315 | - |
|
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2317 | - $item_desc .= 'Message Template'; |
|
| 2318 | - $query_args = array(); |
|
| 2319 | - $edit_array = array(); |
|
| 2320 | - $action_desc = ''; |
|
| 2321 | - |
|
| 2322 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2323 | - if ($new) { |
|
| 2324 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2325 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2326 | - if (empty($edit_array)) { |
|
| 2327 | - $success = 0; |
|
| 2328 | - } else { |
|
| 2329 | - $success = 1; |
|
| 2330 | - $edit_array = $edit_array[0]; |
|
| 2331 | - $query_args = array( |
|
| 2332 | - 'id' => $edit_array['GRP_ID'], |
|
| 2333 | - 'context' => $edit_array['MTP_context'], |
|
| 2334 | - 'action' => 'edit_message_template' |
|
| 2335 | - ); |
|
| 2336 | - } |
|
| 2337 | - } |
|
| 2338 | - $action_desc = 'created'; |
|
| 2339 | - } else { |
|
| 2340 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2341 | - $MTP = EEM_Message_Template::instance(); |
|
| 2266 | + $set_column_values = array( |
|
| 2267 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2268 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2269 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2270 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2271 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2272 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2273 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2274 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2275 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2276 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2277 | + : 0, |
|
| 2278 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2279 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2280 | + : 0, |
|
| 2281 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2282 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2283 | + ); |
|
| 2284 | + |
|
| 2285 | + |
|
| 2286 | + return $set_column_values; |
|
| 2287 | + } |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + protected function _insert_or_update_message_template($new = false) |
|
| 2291 | + { |
|
| 2292 | + |
|
| 2293 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2294 | + $success = 0; |
|
| 2295 | + $override = false; |
|
| 2296 | + |
|
| 2297 | + //setup notices description |
|
| 2298 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2299 | + |
|
| 2300 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2301 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2302 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2303 | + |
|
| 2304 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2305 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2306 | + |
|
| 2307 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2308 | + ? ucwords($message_type_object->label['singular']) |
|
| 2309 | + : ''; |
|
| 2310 | + |
|
| 2311 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2312 | + ? $this->_req_data['MTP_context'] |
|
| 2313 | + : ''; |
|
| 2314 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2315 | + |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2317 | + $item_desc .= 'Message Template'; |
|
| 2318 | + $query_args = array(); |
|
| 2319 | + $edit_array = array(); |
|
| 2320 | + $action_desc = ''; |
|
| 2321 | + |
|
| 2322 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2323 | + if ($new) { |
|
| 2324 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2325 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2326 | + if (empty($edit_array)) { |
|
| 2327 | + $success = 0; |
|
| 2328 | + } else { |
|
| 2329 | + $success = 1; |
|
| 2330 | + $edit_array = $edit_array[0]; |
|
| 2331 | + $query_args = array( |
|
| 2332 | + 'id' => $edit_array['GRP_ID'], |
|
| 2333 | + 'context' => $edit_array['MTP_context'], |
|
| 2334 | + 'action' => 'edit_message_template' |
|
| 2335 | + ); |
|
| 2336 | + } |
|
| 2337 | + } |
|
| 2338 | + $action_desc = 'created'; |
|
| 2339 | + } else { |
|
| 2340 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2341 | + $MTP = EEM_Message_Template::instance(); |
|
| 2342 | 2342 | |
| 2343 | 2343 | |
| 2344 | - //run update for each template field in displayed context |
|
| 2345 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2346 | - EE_Error::add_error( |
|
| 2347 | - __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2348 | - 'event_espresso'), |
|
| 2349 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2350 | - ); |
|
| 2351 | - $success = 0; |
|
| 2344 | + //run update for each template field in displayed context |
|
| 2345 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2346 | + EE_Error::add_error( |
|
| 2347 | + __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2348 | + 'event_espresso'), |
|
| 2349 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2350 | + ); |
|
| 2351 | + $success = 0; |
|
| 2352 | 2352 | |
| 2353 | - } else { |
|
| 2354 | - //first validate all fields! |
|
| 2355 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2356 | - $message_type_slug); |
|
| 2353 | + } else { |
|
| 2354 | + //first validate all fields! |
|
| 2355 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2356 | + $message_type_slug); |
|
| 2357 | 2357 | |
| 2358 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2359 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2360 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2361 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2358 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2359 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2360 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2361 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2362 | 2362 | |
| 2363 | - $success = 0; |
|
| 2363 | + $success = 0; |
|
| 2364 | 2364 | |
| 2365 | - //setup notices |
|
| 2366 | - foreach ($validates as $field => $error) { |
|
| 2367 | - if (isset($error['msg'])) { |
|
| 2368 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2365 | + //setup notices |
|
| 2366 | + foreach ($validates as $field => $error) { |
|
| 2367 | + if (isset($error['msg'])) { |
|
| 2368 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | 2371 | |
| 2372 | - } else { |
|
| 2373 | - $set_column_values = array(); |
|
| 2374 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2375 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2372 | + } else { |
|
| 2373 | + $set_column_values = array(); |
|
| 2374 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2375 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2376 | 2376 | |
| 2377 | - $where_cols_n_values = array( |
|
| 2378 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2379 | - ); |
|
| 2377 | + $where_cols_n_values = array( |
|
| 2378 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2379 | + ); |
|
| 2380 | 2380 | |
| 2381 | - $message_template_fields = array( |
|
| 2382 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2383 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2384 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2385 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2386 | - ); |
|
| 2387 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2388 | - if ($updated === false) { |
|
| 2389 | - EE_Error::add_error( |
|
| 2390 | - sprintf( |
|
| 2391 | - __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2392 | - $template_field |
|
| 2393 | - ), |
|
| 2394 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2395 | - ); |
|
| 2396 | - } else { |
|
| 2397 | - $success = 1; |
|
| 2398 | - } |
|
| 2399 | - } |
|
| 2400 | - $action_desc = 'updated'; |
|
| 2401 | - } |
|
| 2381 | + $message_template_fields = array( |
|
| 2382 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2383 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2384 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2385 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2386 | + ); |
|
| 2387 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2388 | + if ($updated === false) { |
|
| 2389 | + EE_Error::add_error( |
|
| 2390 | + sprintf( |
|
| 2391 | + __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2392 | + $template_field |
|
| 2393 | + ), |
|
| 2394 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2395 | + ); |
|
| 2396 | + } else { |
|
| 2397 | + $success = 1; |
|
| 2398 | + } |
|
| 2399 | + } |
|
| 2400 | + $action_desc = 'updated'; |
|
| 2401 | + } |
|
| 2402 | 2402 | |
| 2403 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2404 | - $mtpg_fields = array( |
|
| 2405 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2406 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2407 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2408 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2409 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2410 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2411 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2412 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2413 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2414 | - : '', |
|
| 2415 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2416 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2417 | - : '' |
|
| 2418 | - ); |
|
| 2403 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2404 | + $mtpg_fields = array( |
|
| 2405 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2406 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2407 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2408 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2409 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2410 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2411 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2412 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2413 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2414 | + : '', |
|
| 2415 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2416 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2417 | + : '' |
|
| 2418 | + ); |
|
| 2419 | 2419 | |
| 2420 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2421 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2420 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2421 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2422 | 2422 | |
| 2423 | - if ($updated === false) { |
|
| 2424 | - EE_Error::add_error( |
|
| 2425 | - sprintf( |
|
| 2426 | - __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2427 | - $set_column_values['GRP_ID'] |
|
| 2428 | - ), |
|
| 2429 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | - ); |
|
| 2431 | - } else { |
|
| 2432 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2433 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2434 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2435 | - : 'default'; |
|
| 2423 | + if ($updated === false) { |
|
| 2424 | + EE_Error::add_error( |
|
| 2425 | + sprintf( |
|
| 2426 | + __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2427 | + $set_column_values['GRP_ID'] |
|
| 2428 | + ), |
|
| 2429 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | + ); |
|
| 2431 | + } else { |
|
| 2432 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2433 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2434 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2435 | + : 'default'; |
|
| 2436 | 2436 | |
| 2437 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2438 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2439 | - : 'default'; |
|
| 2437 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2438 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2439 | + : 'default'; |
|
| 2440 | 2440 | |
| 2441 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2442 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2443 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2444 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2445 | - } |
|
| 2446 | - $success = 1; |
|
| 2447 | - } |
|
| 2448 | - } |
|
| 2449 | - } |
|
| 2441 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2442 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2443 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2444 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2445 | + } |
|
| 2446 | + $success = 1; |
|
| 2447 | + } |
|
| 2448 | + } |
|
| 2449 | + } |
|
| 2450 | 2450 | |
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - //we return things differently if doing ajax |
|
| 2454 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2455 | - $this->_template_args['success'] = $success; |
|
| 2456 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2457 | - $this->_template_args['content'] = ''; |
|
| 2458 | - $this->_template_args['data'] = array( |
|
| 2459 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2460 | - 'templateName' => $edit_array['template_name'] |
|
| 2461 | - ); |
|
| 2462 | - if ($success) { |
|
| 2463 | - EE_Error::overwrite_success(); |
|
| 2464 | - EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2465 | - 'event_espresso')); |
|
| 2466 | - } |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + //we return things differently if doing ajax |
|
| 2454 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2455 | + $this->_template_args['success'] = $success; |
|
| 2456 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2457 | + $this->_template_args['content'] = ''; |
|
| 2458 | + $this->_template_args['data'] = array( |
|
| 2459 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2460 | + 'templateName' => $edit_array['template_name'] |
|
| 2461 | + ); |
|
| 2462 | + if ($success) { |
|
| 2463 | + EE_Error::overwrite_success(); |
|
| 2464 | + EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2465 | + 'event_espresso')); |
|
| 2466 | + } |
|
| 2467 | 2467 | |
| 2468 | - $this->_return_json(); |
|
| 2469 | - } |
|
| 2470 | - |
|
| 2471 | - |
|
| 2472 | - //was a test send triggered? |
|
| 2473 | - if (isset($this->_req_data['test_button'])) { |
|
| 2474 | - EE_Error::overwrite_success(); |
|
| 2475 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2476 | - $override = true; |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - if (empty($query_args)) { |
|
| 2480 | - $query_args = array( |
|
| 2481 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2482 | - 'context' => $context_slug, |
|
| 2483 | - 'action' => 'edit_message_template' |
|
| 2484 | - ); |
|
| 2485 | - } |
|
| 2486 | - |
|
| 2487 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - /** |
|
| 2492 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2493 | - * |
|
| 2494 | - * @param string $context what context being tested |
|
| 2495 | - * @param string $messenger messenger being tested |
|
| 2496 | - * @param string $message_type message type being tested |
|
| 2497 | - * |
|
| 2498 | - */ |
|
| 2499 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2500 | - { |
|
| 2501 | - //set things up for preview |
|
| 2502 | - $this->_req_data['messenger'] = $messenger; |
|
| 2503 | - $this->_req_data['message_type'] = $message_type; |
|
| 2504 | - $this->_req_data['context'] = $context; |
|
| 2505 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2506 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2507 | - |
|
| 2508 | - //let's save any existing fields that might be required by the messenger |
|
| 2509 | - if ( |
|
| 2510 | - isset($this->_req_data['test_settings_fld']) |
|
| 2511 | - && $active_messenger instanceof EE_messenger |
|
| 2512 | - ) { |
|
| 2513 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2514 | - } |
|
| 2515 | - |
|
| 2516 | - $success = $this->_preview_message(true); |
|
| 2517 | - |
|
| 2518 | - if ($success) { |
|
| 2519 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2520 | - } else { |
|
| 2521 | - EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2522 | - __LINE__); |
|
| 2523 | - } |
|
| 2524 | - } |
|
| 2525 | - |
|
| 2526 | - |
|
| 2527 | - /** |
|
| 2528 | - * _generate_new_templates |
|
| 2529 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2530 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2531 | - * for the event. |
|
| 2532 | - * |
|
| 2533 | - * |
|
| 2534 | - * @param string $messenger the messenger we are generating templates for |
|
| 2535 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2536 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2537 | - * indicate the message_template_group being used as the base. |
|
| 2538 | - * |
|
| 2539 | - * @param bool $global |
|
| 2540 | - * |
|
| 2541 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2542 | - * encountering problems. |
|
| 2543 | - * @throws \EE_Error |
|
| 2544 | - */ |
|
| 2545 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2546 | - { |
|
| 2547 | - |
|
| 2548 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2549 | - if (empty($message_types)) { |
|
| 2550 | - return true; |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2554 | - } |
|
| 2555 | - |
|
| 2556 | - |
|
| 2557 | - /** |
|
| 2558 | - * [_trash_or_restore_message_template] |
|
| 2559 | - * |
|
| 2560 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2561 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2562 | - * an individual context (FALSE). |
|
| 2563 | - * |
|
| 2564 | - * @return void |
|
| 2565 | - */ |
|
| 2566 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2567 | - { |
|
| 2568 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2569 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2570 | - |
|
| 2571 | - $success = 1; |
|
| 2572 | - |
|
| 2573 | - //incoming GRP_IDs |
|
| 2574 | - if ($all) { |
|
| 2575 | - //Checkboxes |
|
| 2576 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2577 | - //if array has more than one element then success message should be plural. |
|
| 2578 | - //todo: what about nonce? |
|
| 2579 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2468 | + $this->_return_json(); |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + |
|
| 2472 | + //was a test send triggered? |
|
| 2473 | + if (isset($this->_req_data['test_button'])) { |
|
| 2474 | + EE_Error::overwrite_success(); |
|
| 2475 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2476 | + $override = true; |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + if (empty($query_args)) { |
|
| 2480 | + $query_args = array( |
|
| 2481 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2482 | + 'context' => $context_slug, |
|
| 2483 | + 'action' => 'edit_message_template' |
|
| 2484 | + ); |
|
| 2485 | + } |
|
| 2486 | + |
|
| 2487 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + /** |
|
| 2492 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2493 | + * |
|
| 2494 | + * @param string $context what context being tested |
|
| 2495 | + * @param string $messenger messenger being tested |
|
| 2496 | + * @param string $message_type message type being tested |
|
| 2497 | + * |
|
| 2498 | + */ |
|
| 2499 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2500 | + { |
|
| 2501 | + //set things up for preview |
|
| 2502 | + $this->_req_data['messenger'] = $messenger; |
|
| 2503 | + $this->_req_data['message_type'] = $message_type; |
|
| 2504 | + $this->_req_data['context'] = $context; |
|
| 2505 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2506 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2507 | + |
|
| 2508 | + //let's save any existing fields that might be required by the messenger |
|
| 2509 | + if ( |
|
| 2510 | + isset($this->_req_data['test_settings_fld']) |
|
| 2511 | + && $active_messenger instanceof EE_messenger |
|
| 2512 | + ) { |
|
| 2513 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2514 | + } |
|
| 2515 | + |
|
| 2516 | + $success = $this->_preview_message(true); |
|
| 2517 | + |
|
| 2518 | + if ($success) { |
|
| 2519 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2520 | + } else { |
|
| 2521 | + EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2522 | + __LINE__); |
|
| 2523 | + } |
|
| 2524 | + } |
|
| 2525 | + |
|
| 2526 | + |
|
| 2527 | + /** |
|
| 2528 | + * _generate_new_templates |
|
| 2529 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2530 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2531 | + * for the event. |
|
| 2532 | + * |
|
| 2533 | + * |
|
| 2534 | + * @param string $messenger the messenger we are generating templates for |
|
| 2535 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2536 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2537 | + * indicate the message_template_group being used as the base. |
|
| 2538 | + * |
|
| 2539 | + * @param bool $global |
|
| 2540 | + * |
|
| 2541 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2542 | + * encountering problems. |
|
| 2543 | + * @throws \EE_Error |
|
| 2544 | + */ |
|
| 2545 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2546 | + { |
|
| 2547 | + |
|
| 2548 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2549 | + if (empty($message_types)) { |
|
| 2550 | + return true; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + |
|
| 2557 | + /** |
|
| 2558 | + * [_trash_or_restore_message_template] |
|
| 2559 | + * |
|
| 2560 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2561 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2562 | + * an individual context (FALSE). |
|
| 2563 | + * |
|
| 2564 | + * @return void |
|
| 2565 | + */ |
|
| 2566 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2567 | + { |
|
| 2568 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2569 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2570 | + |
|
| 2571 | + $success = 1; |
|
| 2572 | + |
|
| 2573 | + //incoming GRP_IDs |
|
| 2574 | + if ($all) { |
|
| 2575 | + //Checkboxes |
|
| 2576 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2577 | + //if array has more than one element then success message should be plural. |
|
| 2578 | + //todo: what about nonce? |
|
| 2579 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2580 | 2580 | |
| 2581 | - //cycle through checkboxes |
|
| 2582 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2583 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2584 | - if ( ! $trashed_or_restored) { |
|
| 2585 | - $success = 0; |
|
| 2586 | - } |
|
| 2587 | - } |
|
| 2588 | - } else { |
|
| 2589 | - //grab single GRP_ID and handle |
|
| 2590 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2591 | - if ( ! empty($GRP_ID)) { |
|
| 2592 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2593 | - if ( ! $trashed_or_restored) { |
|
| 2594 | - $success = 0; |
|
| 2595 | - } |
|
| 2596 | - } else { |
|
| 2597 | - $success = 0; |
|
| 2598 | - } |
|
| 2599 | - } |
|
| 2581 | + //cycle through checkboxes |
|
| 2582 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2583 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2584 | + if ( ! $trashed_or_restored) { |
|
| 2585 | + $success = 0; |
|
| 2586 | + } |
|
| 2587 | + } |
|
| 2588 | + } else { |
|
| 2589 | + //grab single GRP_ID and handle |
|
| 2590 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2591 | + if ( ! empty($GRP_ID)) { |
|
| 2592 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2593 | + if ( ! $trashed_or_restored) { |
|
| 2594 | + $success = 0; |
|
| 2595 | + } |
|
| 2596 | + } else { |
|
| 2597 | + $success = 0; |
|
| 2598 | + } |
|
| 2599 | + } |
|
| 2600 | 2600 | |
| 2601 | - } |
|
| 2601 | + } |
|
| 2602 | 2602 | |
| 2603 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2603 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2604 | 2604 | |
| 2605 | - $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2605 | + $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2606 | 2606 | |
| 2607 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2608 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2607 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2608 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2609 | 2609 | |
| 2610 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2611 | - 'event_espresso') : $item_desc; |
|
| 2610 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2611 | + 'event_espresso') : $item_desc; |
|
| 2612 | 2612 | |
| 2613 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2613 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2614 | 2614 | |
| 2615 | - } |
|
| 2615 | + } |
|
| 2616 | 2616 | |
| 2617 | 2617 | |
| 2618 | - /** |
|
| 2619 | - * [_delete_message_template] |
|
| 2620 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2621 | - * @return void |
|
| 2622 | - */ |
|
| 2623 | - protected function _delete_message_template() |
|
| 2624 | - { |
|
| 2625 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2618 | + /** |
|
| 2619 | + * [_delete_message_template] |
|
| 2620 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2621 | + * @return void |
|
| 2622 | + */ |
|
| 2623 | + protected function _delete_message_template() |
|
| 2624 | + { |
|
| 2625 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2626 | 2626 | |
| 2627 | - //checkboxes |
|
| 2628 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2629 | - //if array has more than one element then success message should be plural |
|
| 2630 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2627 | + //checkboxes |
|
| 2628 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2629 | + //if array has more than one element then success message should be plural |
|
| 2630 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2631 | 2631 | |
| 2632 | - //cycle through bulk action checkboxes |
|
| 2633 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2634 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2635 | - } |
|
| 2636 | - } else { |
|
| 2637 | - //grab single grp_id and delete |
|
| 2638 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 2639 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2640 | - } |
|
| 2641 | - |
|
| 2642 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2643 | - |
|
| 2644 | - } |
|
| 2645 | - |
|
| 2646 | - |
|
| 2647 | - /** |
|
| 2648 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 2649 | - * |
|
| 2650 | - * @param int $GRP_ID The group being deleted |
|
| 2651 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2652 | - * |
|
| 2653 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2654 | - */ |
|
| 2655 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2656 | - { |
|
| 2657 | - $success = 1; |
|
| 2658 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2659 | - //first let's GET this group |
|
| 2660 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2661 | - //then delete permanently all the related Message Templates |
|
| 2662 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2663 | - |
|
| 2664 | - if ($deleted === 0) { |
|
| 2665 | - $success = 0; |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - //now delete permanently this particular group |
|
| 2669 | - |
|
| 2670 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2671 | - $success = 0; |
|
| 2672 | - } |
|
| 2673 | - |
|
| 2674 | - return $success; |
|
| 2675 | - } |
|
| 2676 | - |
|
| 2677 | - |
|
| 2678 | - /** |
|
| 2679 | - * _learn_more_about_message_templates_link |
|
| 2680 | - * @access protected |
|
| 2681 | - * @return string |
|
| 2682 | - */ |
|
| 2683 | - protected function _learn_more_about_message_templates_link() |
|
| 2684 | - { |
|
| 2685 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2686 | - 'event_espresso') . '</a>'; |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - |
|
| 2690 | - /** |
|
| 2691 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2692 | - * ajax and other routes. |
|
| 2693 | - * @return void |
|
| 2694 | - */ |
|
| 2695 | - protected function _settings() |
|
| 2696 | - { |
|
| 2697 | - |
|
| 2698 | - |
|
| 2699 | - $this->_set_m_mt_settings(); |
|
| 2700 | - |
|
| 2701 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2702 | - |
|
| 2703 | - //let's setup the messenger tabs |
|
| 2704 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2705 | - 'messenger_links', '|', $selected_messenger); |
|
| 2706 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2707 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2708 | - |
|
| 2709 | - $this->display_admin_page_with_sidebar(); |
|
| 2710 | - |
|
| 2711 | - } |
|
| 2712 | - |
|
| 2713 | - |
|
| 2714 | - /** |
|
| 2715 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2716 | - * |
|
| 2717 | - * @access protected |
|
| 2718 | - * @return void |
|
| 2719 | - */ |
|
| 2720 | - protected function _set_m_mt_settings() |
|
| 2721 | - { |
|
| 2722 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 2723 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 2724 | - return; |
|
| 2725 | - } |
|
| 2726 | - |
|
| 2727 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2728 | - |
|
| 2729 | - //get all installed messengers and message_types |
|
| 2730 | - /** @type EE_messenger[] $messengers */ |
|
| 2731 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2732 | - /** @type EE_message_type[] $message_types */ |
|
| 2733 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2734 | - |
|
| 2735 | - |
|
| 2736 | - //assemble the array for the _tab_text_links helper |
|
| 2737 | - |
|
| 2738 | - foreach ($messengers as $messenger) { |
|
| 2739 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2740 | - 'label' => ucwords($messenger->label['singular']), |
|
| 2741 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2742 | - 'href' => $messenger->name, |
|
| 2743 | - 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2744 | - 'slug' => $messenger->name, |
|
| 2745 | - 'obj' => $messenger |
|
| 2746 | - ); |
|
| 2632 | + //cycle through bulk action checkboxes |
|
| 2633 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2634 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2635 | + } |
|
| 2636 | + } else { |
|
| 2637 | + //grab single grp_id and delete |
|
| 2638 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 2639 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2640 | + } |
|
| 2641 | + |
|
| 2642 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2643 | + |
|
| 2644 | + } |
|
| 2645 | + |
|
| 2646 | + |
|
| 2647 | + /** |
|
| 2648 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 2649 | + * |
|
| 2650 | + * @param int $GRP_ID The group being deleted |
|
| 2651 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2652 | + * |
|
| 2653 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 2654 | + */ |
|
| 2655 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2656 | + { |
|
| 2657 | + $success = 1; |
|
| 2658 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2659 | + //first let's GET this group |
|
| 2660 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2661 | + //then delete permanently all the related Message Templates |
|
| 2662 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2663 | + |
|
| 2664 | + if ($deleted === 0) { |
|
| 2665 | + $success = 0; |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + //now delete permanently this particular group |
|
| 2669 | + |
|
| 2670 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2671 | + $success = 0; |
|
| 2672 | + } |
|
| 2673 | + |
|
| 2674 | + return $success; |
|
| 2675 | + } |
|
| 2676 | + |
|
| 2677 | + |
|
| 2678 | + /** |
|
| 2679 | + * _learn_more_about_message_templates_link |
|
| 2680 | + * @access protected |
|
| 2681 | + * @return string |
|
| 2682 | + */ |
|
| 2683 | + protected function _learn_more_about_message_templates_link() |
|
| 2684 | + { |
|
| 2685 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2686 | + 'event_espresso') . '</a>'; |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2692 | + * ajax and other routes. |
|
| 2693 | + * @return void |
|
| 2694 | + */ |
|
| 2695 | + protected function _settings() |
|
| 2696 | + { |
|
| 2697 | + |
|
| 2698 | + |
|
| 2699 | + $this->_set_m_mt_settings(); |
|
| 2700 | + |
|
| 2701 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2702 | + |
|
| 2703 | + //let's setup the messenger tabs |
|
| 2704 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2705 | + 'messenger_links', '|', $selected_messenger); |
|
| 2706 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2707 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2708 | + |
|
| 2709 | + $this->display_admin_page_with_sidebar(); |
|
| 2710 | + |
|
| 2711 | + } |
|
| 2712 | + |
|
| 2713 | + |
|
| 2714 | + /** |
|
| 2715 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2716 | + * |
|
| 2717 | + * @access protected |
|
| 2718 | + * @return void |
|
| 2719 | + */ |
|
| 2720 | + protected function _set_m_mt_settings() |
|
| 2721 | + { |
|
| 2722 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 2723 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 2724 | + return; |
|
| 2725 | + } |
|
| 2726 | + |
|
| 2727 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2728 | + |
|
| 2729 | + //get all installed messengers and message_types |
|
| 2730 | + /** @type EE_messenger[] $messengers */ |
|
| 2731 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2732 | + /** @type EE_message_type[] $message_types */ |
|
| 2733 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2734 | + |
|
| 2735 | + |
|
| 2736 | + //assemble the array for the _tab_text_links helper |
|
| 2737 | + |
|
| 2738 | + foreach ($messengers as $messenger) { |
|
| 2739 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2740 | + 'label' => ucwords($messenger->label['singular']), |
|
| 2741 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2742 | + 'href' => $messenger->name, |
|
| 2743 | + 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2744 | + 'slug' => $messenger->name, |
|
| 2745 | + 'obj' => $messenger |
|
| 2746 | + ); |
|
| 2747 | 2747 | |
| 2748 | 2748 | |
| 2749 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2749 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2750 | 2750 | |
| 2751 | - foreach ($message_types as $message_type) { |
|
| 2752 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2753 | - if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2754 | - continue; |
|
| 2755 | - } |
|
| 2751 | + foreach ($message_types as $message_type) { |
|
| 2752 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2753 | + if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2754 | + continue; |
|
| 2755 | + } |
|
| 2756 | 2756 | |
| 2757 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2758 | - $message_type->name) ? 'active' : 'inactive'; |
|
| 2757 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2758 | + $message_type->name) ? 'active' : 'inactive'; |
|
| 2759 | 2759 | |
| 2760 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2761 | - 'label' => ucwords($message_type->label['singular']), |
|
| 2762 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2763 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2764 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2765 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2766 | - 'title' => $a_or_i == 'active' |
|
| 2767 | - ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2768 | - : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2769 | - 'content' => $a_or_i == 'active' |
|
| 2770 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2771 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2772 | - 'slug' => $message_type->name, |
|
| 2773 | - 'active' => $a_or_i == 'active' ? true : false, |
|
| 2774 | - 'obj' => $message_type |
|
| 2775 | - ); |
|
| 2776 | - } |
|
| 2777 | - } |
|
| 2778 | - } |
|
| 2779 | - |
|
| 2780 | - |
|
| 2781 | - /** |
|
| 2782 | - * This just prepares the content for the message type settings |
|
| 2783 | - * |
|
| 2784 | - * @param object $message_type The message type object |
|
| 2785 | - * @param object $messenger The messenger object |
|
| 2786 | - * @param boolean $active Whether the message type is active or not |
|
| 2787 | - * |
|
| 2788 | - * @return string html output for the content |
|
| 2789 | - */ |
|
| 2790 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2791 | - { |
|
| 2792 | - //get message type fields |
|
| 2793 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 2794 | - $settings_template_args['template_form_fields'] = ''; |
|
| 2795 | - |
|
| 2796 | - if ( ! empty($fields) && $active) { |
|
| 2760 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2761 | + 'label' => ucwords($message_type->label['singular']), |
|
| 2762 | + 'class' => 'message-type-' . $a_or_i, |
|
| 2763 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2764 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2765 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2766 | + 'title' => $a_or_i == 'active' |
|
| 2767 | + ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2768 | + : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2769 | + 'content' => $a_or_i == 'active' |
|
| 2770 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2771 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2772 | + 'slug' => $message_type->name, |
|
| 2773 | + 'active' => $a_or_i == 'active' ? true : false, |
|
| 2774 | + 'obj' => $message_type |
|
| 2775 | + ); |
|
| 2776 | + } |
|
| 2777 | + } |
|
| 2778 | + } |
|
| 2779 | + |
|
| 2780 | + |
|
| 2781 | + /** |
|
| 2782 | + * This just prepares the content for the message type settings |
|
| 2783 | + * |
|
| 2784 | + * @param object $message_type The message type object |
|
| 2785 | + * @param object $messenger The messenger object |
|
| 2786 | + * @param boolean $active Whether the message type is active or not |
|
| 2787 | + * |
|
| 2788 | + * @return string html output for the content |
|
| 2789 | + */ |
|
| 2790 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2791 | + { |
|
| 2792 | + //get message type fields |
|
| 2793 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 2794 | + $settings_template_args['template_form_fields'] = ''; |
|
| 2795 | + |
|
| 2796 | + if ( ! empty($fields) && $active) { |
|
| 2797 | 2797 | |
| 2798 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2798 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2799 | 2799 | |
| 2800 | - foreach ($fields as $fldname => $fldprops) { |
|
| 2801 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2802 | - $template_form_field[$field_id] = array( |
|
| 2803 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2804 | - 'label' => $fldprops['label'], |
|
| 2805 | - 'input' => $fldprops['field_type'], |
|
| 2806 | - 'type' => $fldprops['value_type'], |
|
| 2807 | - 'required' => $fldprops['required'], |
|
| 2808 | - 'validation' => $fldprops['validation'], |
|
| 2809 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2810 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2811 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2812 | - 'css_class' => 'no-drag', |
|
| 2813 | - 'format' => $fldprops['format'] |
|
| 2814 | - ); |
|
| 2815 | - } |
|
| 2800 | + foreach ($fields as $fldname => $fldprops) { |
|
| 2801 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2802 | + $template_form_field[$field_id] = array( |
|
| 2803 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2804 | + 'label' => $fldprops['label'], |
|
| 2805 | + 'input' => $fldprops['field_type'], |
|
| 2806 | + 'type' => $fldprops['value_type'], |
|
| 2807 | + 'required' => $fldprops['required'], |
|
| 2808 | + 'validation' => $fldprops['validation'], |
|
| 2809 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2810 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2811 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2812 | + 'css_class' => 'no-drag', |
|
| 2813 | + 'format' => $fldprops['format'] |
|
| 2814 | + ); |
|
| 2815 | + } |
|
| 2816 | 2816 | |
| 2817 | 2817 | |
| 2818 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2819 | - 'string', 'ee_mt_activate_form') : ''; |
|
| 2820 | - } |
|
| 2821 | - |
|
| 2822 | - $settings_template_args['description'] = $message_type->description; |
|
| 2823 | - //we also need some hidden fields |
|
| 2824 | - $settings_template_args['hidden_fields'] = array( |
|
| 2825 | - 'message_type_settings[messenger]' => array( |
|
| 2826 | - 'type' => 'hidden', |
|
| 2827 | - 'value' => $messenger->name |
|
| 2828 | - ), |
|
| 2829 | - 'message_type_settings[message_type]' => array( |
|
| 2830 | - 'type' => 'hidden', |
|
| 2831 | - 'value' => $message_type->name |
|
| 2832 | - ), |
|
| 2833 | - 'type' => array( |
|
| 2834 | - 'type' => 'hidden', |
|
| 2835 | - 'value' => 'message_type' |
|
| 2836 | - ) |
|
| 2837 | - ); |
|
| 2838 | - |
|
| 2839 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2840 | - 'array'); |
|
| 2841 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2842 | - |
|
| 2843 | - |
|
| 2844 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2845 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2846 | - |
|
| 2847 | - return $content; |
|
| 2848 | - } |
|
| 2849 | - |
|
| 2850 | - |
|
| 2851 | - /** |
|
| 2852 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2853 | - * |
|
| 2854 | - * @access protected |
|
| 2855 | - * @return void |
|
| 2856 | - */ |
|
| 2857 | - protected function _messages_settings_metaboxes() |
|
| 2858 | - { |
|
| 2859 | - $this->_set_m_mt_settings(); |
|
| 2860 | - $m_boxes = $mt_boxes = array(); |
|
| 2861 | - $m_template_args = $mt_template_args = array(); |
|
| 2862 | - |
|
| 2863 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2864 | - |
|
| 2865 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2866 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2867 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2868 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2869 | - //messenger meta boxes |
|
| 2870 | - $active = $selected_messenger == $messenger ? true : false; |
|
| 2871 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2872 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2873 | - : ''; |
|
| 2874 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2875 | - __('%s Settings', 'event_espresso'), |
|
| 2876 | - $tab_array['label'] |
|
| 2877 | - ); |
|
| 2878 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2879 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2880 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2881 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2882 | - : '', |
|
| 2883 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2884 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2885 | - 'hide_on_message' => $hide_on_message, |
|
| 2886 | - 'messenger' => $messenger, |
|
| 2887 | - 'active' => $active |
|
| 2888 | - ); |
|
| 2889 | - // message type meta boxes |
|
| 2890 | - // (which is really just the inactive container for each messenger |
|
| 2891 | - // showing inactive message types for that messenger) |
|
| 2892 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2893 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2894 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2895 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2896 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2897 | - : '', |
|
| 2898 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2899 | - 'hide_on_message' => $hide_on_message, |
|
| 2900 | - 'hide_off_message' => $hide_off_message, |
|
| 2901 | - 'messenger' => $messenger, |
|
| 2902 | - 'active' => $active |
|
| 2903 | - ); |
|
| 2904 | - } |
|
| 2905 | - } |
|
| 2906 | - |
|
| 2907 | - |
|
| 2908 | - //register messenger metaboxes |
|
| 2909 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2910 | - foreach ($m_boxes as $box => $label) { |
|
| 2911 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2912 | - $msgr = str_replace('_a_box', '', $box); |
|
| 2913 | - add_meta_box( |
|
| 2914 | - 'espresso_' . $msgr . '_settings', |
|
| 2915 | - $label, |
|
| 2916 | - function ($post, $metabox) { |
|
| 2917 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2918 | - $metabox["args"]["template_args"], true); |
|
| 2919 | - }, |
|
| 2920 | - $this->_current_screen->id, |
|
| 2921 | - 'normal', |
|
| 2922 | - 'high', |
|
| 2923 | - $callback_args |
|
| 2924 | - ); |
|
| 2925 | - } |
|
| 2926 | - |
|
| 2927 | - //register message type metaboxes |
|
| 2928 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2929 | - foreach ($mt_boxes as $box => $label) { |
|
| 2930 | - $callback_args = array( |
|
| 2931 | - 'template_path' => $mt_template_path, |
|
| 2932 | - 'template_args' => $mt_template_args[$box] |
|
| 2933 | - ); |
|
| 2934 | - $mt = str_replace('_i_box', '', $box); |
|
| 2935 | - add_meta_box( |
|
| 2936 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2937 | - $label, |
|
| 2938 | - function ($post, $metabox) { |
|
| 2939 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2940 | - $metabox["args"]["template_args"], true); |
|
| 2941 | - }, |
|
| 2942 | - $this->_current_screen->id, |
|
| 2943 | - 'side', |
|
| 2944 | - 'high', |
|
| 2945 | - $callback_args |
|
| 2946 | - ); |
|
| 2947 | - } |
|
| 2948 | - |
|
| 2949 | - //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2950 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2951 | - if (is_main_site()) { |
|
| 2952 | - add_meta_box( |
|
| 2953 | - 'espresso_global_message_settings', |
|
| 2954 | - __('Global Message Settings', 'event_espresso'), |
|
| 2955 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 2956 | - $this->_current_screen->id, |
|
| 2957 | - 'normal', |
|
| 2958 | - 'low', |
|
| 2959 | - array() |
|
| 2960 | - ); |
|
| 2961 | - } |
|
| 2962 | - |
|
| 2963 | - } |
|
| 2964 | - |
|
| 2965 | - |
|
| 2966 | - /** |
|
| 2967 | - * This generates the content for the global messages settings metabox. |
|
| 2968 | - * @return string |
|
| 2969 | - */ |
|
| 2970 | - public function global_messages_settings_metabox_content() |
|
| 2971 | - { |
|
| 2972 | - $form = $this->_generate_global_settings_form(); |
|
| 2973 | - echo $form->form_open( |
|
| 2974 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2975 | - 'POST' |
|
| 2976 | - ) |
|
| 2977 | - . $form->get_html() |
|
| 2978 | - . $form->form_close(); |
|
| 2979 | - } |
|
| 2980 | - |
|
| 2981 | - |
|
| 2982 | - /** |
|
| 2983 | - * This generates and returns the form object for the global messages settings. |
|
| 2984 | - * @return EE_Form_Section_Proper |
|
| 2985 | - */ |
|
| 2986 | - protected function _generate_global_settings_form() |
|
| 2987 | - { |
|
| 2988 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 2989 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 2990 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2991 | - |
|
| 2992 | - return new EE_Form_Section_Proper( |
|
| 2993 | - array( |
|
| 2994 | - 'name' => 'global_messages_settings', |
|
| 2995 | - 'html_id' => 'global_messages_settings', |
|
| 2996 | - 'html_class' => 'form-table', |
|
| 2997 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2998 | - 'subsections' => apply_filters( |
|
| 2999 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3000 | - array( |
|
| 3001 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3002 | - array( |
|
| 3003 | - true => __("On the same request", "event_espresso"), |
|
| 3004 | - false => __("On a separate request", "event_espresso") |
|
| 3005 | - ), |
|
| 3006 | - array( |
|
| 3007 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3008 | - 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 3009 | - 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3010 | - 'event_espresso'), |
|
| 3011 | - ) |
|
| 3012 | - ), |
|
| 3013 | - 'update_settings' => new EE_Submit_Input( |
|
| 3014 | - array( |
|
| 3015 | - 'default' => __('Update', 'event_espresso'), |
|
| 3016 | - 'html_label_text' => ' ' |
|
| 3017 | - ) |
|
| 3018 | - ) |
|
| 3019 | - ) |
|
| 3020 | - ) |
|
| 3021 | - ) |
|
| 3022 | - ); |
|
| 3023 | - } |
|
| 3024 | - |
|
| 3025 | - |
|
| 3026 | - /** |
|
| 3027 | - * This handles updating the global settings set on the admin page. |
|
| 3028 | - * @throws \EE_Error |
|
| 3029 | - */ |
|
| 3030 | - protected function _update_global_settings() |
|
| 3031 | - { |
|
| 3032 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3033 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3034 | - $form = $this->_generate_global_settings_form(); |
|
| 3035 | - if ($form->was_submitted()) { |
|
| 3036 | - $form->receive_form_submission(); |
|
| 3037 | - if ($form->is_valid()) { |
|
| 3038 | - $valid_data = $form->valid_data(); |
|
| 3039 | - foreach ($valid_data as $property => $value) { |
|
| 3040 | - $setter = 'set_' . $property; |
|
| 3041 | - if (method_exists($network_config, $setter)) { |
|
| 3042 | - $network_config->{$setter}($value); |
|
| 3043 | - } else if ( |
|
| 3044 | - property_exists($network_config, $property) |
|
| 3045 | - && $network_config->{$property} !== $value |
|
| 3046 | - ) { |
|
| 3047 | - $network_config->{$property} = $value; |
|
| 3048 | - } |
|
| 3049 | - } |
|
| 3050 | - //only update if the form submission was valid! |
|
| 3051 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3052 | - EE_Error::overwrite_success(); |
|
| 3053 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3054 | - } |
|
| 3055 | - } |
|
| 3056 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3057 | - } |
|
| 3058 | - |
|
| 3059 | - |
|
| 3060 | - /** |
|
| 3061 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3062 | - * |
|
| 3063 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3064 | - * |
|
| 3065 | - * @return string html formatted tabs |
|
| 3066 | - */ |
|
| 3067 | - protected function _get_mt_tabs($tab_array) |
|
| 3068 | - { |
|
| 3069 | - $tab_array = (array)$tab_array; |
|
| 3070 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3071 | - $tabs = ''; |
|
| 3072 | - |
|
| 3073 | - foreach ($tab_array as $tab) { |
|
| 3074 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3075 | - } |
|
| 3076 | - |
|
| 3077 | - return $tabs; |
|
| 3078 | - } |
|
| 3079 | - |
|
| 3080 | - |
|
| 3081 | - /** |
|
| 3082 | - * This prepares the content of the messenger meta box admin settings |
|
| 3083 | - * |
|
| 3084 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3085 | - * |
|
| 3086 | - * @return string html formatted content |
|
| 3087 | - */ |
|
| 3088 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3089 | - { |
|
| 3090 | - |
|
| 3091 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3092 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3093 | - |
|
| 3094 | - //is $messenger active? |
|
| 3095 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3096 | - |
|
| 3097 | - |
|
| 3098 | - if ( ! empty($fields)) { |
|
| 2818 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2819 | + 'string', 'ee_mt_activate_form') : ''; |
|
| 2820 | + } |
|
| 2821 | + |
|
| 2822 | + $settings_template_args['description'] = $message_type->description; |
|
| 2823 | + //we also need some hidden fields |
|
| 2824 | + $settings_template_args['hidden_fields'] = array( |
|
| 2825 | + 'message_type_settings[messenger]' => array( |
|
| 2826 | + 'type' => 'hidden', |
|
| 2827 | + 'value' => $messenger->name |
|
| 2828 | + ), |
|
| 2829 | + 'message_type_settings[message_type]' => array( |
|
| 2830 | + 'type' => 'hidden', |
|
| 2831 | + 'value' => $message_type->name |
|
| 2832 | + ), |
|
| 2833 | + 'type' => array( |
|
| 2834 | + 'type' => 'hidden', |
|
| 2835 | + 'value' => 'message_type' |
|
| 2836 | + ) |
|
| 2837 | + ); |
|
| 2838 | + |
|
| 2839 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2840 | + 'array'); |
|
| 2841 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2842 | + |
|
| 2843 | + |
|
| 2844 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2845 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2846 | + |
|
| 2847 | + return $content; |
|
| 2848 | + } |
|
| 2849 | + |
|
| 2850 | + |
|
| 2851 | + /** |
|
| 2852 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2853 | + * |
|
| 2854 | + * @access protected |
|
| 2855 | + * @return void |
|
| 2856 | + */ |
|
| 2857 | + protected function _messages_settings_metaboxes() |
|
| 2858 | + { |
|
| 2859 | + $this->_set_m_mt_settings(); |
|
| 2860 | + $m_boxes = $mt_boxes = array(); |
|
| 2861 | + $m_template_args = $mt_template_args = array(); |
|
| 2862 | + |
|
| 2863 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2864 | + |
|
| 2865 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2866 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2867 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2868 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2869 | + //messenger meta boxes |
|
| 2870 | + $active = $selected_messenger == $messenger ? true : false; |
|
| 2871 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2872 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2873 | + : ''; |
|
| 2874 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2875 | + __('%s Settings', 'event_espresso'), |
|
| 2876 | + $tab_array['label'] |
|
| 2877 | + ); |
|
| 2878 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 2879 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2880 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2881 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2882 | + : '', |
|
| 2883 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2884 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2885 | + 'hide_on_message' => $hide_on_message, |
|
| 2886 | + 'messenger' => $messenger, |
|
| 2887 | + 'active' => $active |
|
| 2888 | + ); |
|
| 2889 | + // message type meta boxes |
|
| 2890 | + // (which is really just the inactive container for each messenger |
|
| 2891 | + // showing inactive message types for that messenger) |
|
| 2892 | + $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2893 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2894 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2895 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2896 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2897 | + : '', |
|
| 2898 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2899 | + 'hide_on_message' => $hide_on_message, |
|
| 2900 | + 'hide_off_message' => $hide_off_message, |
|
| 2901 | + 'messenger' => $messenger, |
|
| 2902 | + 'active' => $active |
|
| 2903 | + ); |
|
| 2904 | + } |
|
| 2905 | + } |
|
| 2906 | + |
|
| 2907 | + |
|
| 2908 | + //register messenger metaboxes |
|
| 2909 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2910 | + foreach ($m_boxes as $box => $label) { |
|
| 2911 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2912 | + $msgr = str_replace('_a_box', '', $box); |
|
| 2913 | + add_meta_box( |
|
| 2914 | + 'espresso_' . $msgr . '_settings', |
|
| 2915 | + $label, |
|
| 2916 | + function ($post, $metabox) { |
|
| 2917 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2918 | + $metabox["args"]["template_args"], true); |
|
| 2919 | + }, |
|
| 2920 | + $this->_current_screen->id, |
|
| 2921 | + 'normal', |
|
| 2922 | + 'high', |
|
| 2923 | + $callback_args |
|
| 2924 | + ); |
|
| 2925 | + } |
|
| 2926 | + |
|
| 2927 | + //register message type metaboxes |
|
| 2928 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2929 | + foreach ($mt_boxes as $box => $label) { |
|
| 2930 | + $callback_args = array( |
|
| 2931 | + 'template_path' => $mt_template_path, |
|
| 2932 | + 'template_args' => $mt_template_args[$box] |
|
| 2933 | + ); |
|
| 2934 | + $mt = str_replace('_i_box', '', $box); |
|
| 2935 | + add_meta_box( |
|
| 2936 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 2937 | + $label, |
|
| 2938 | + function ($post, $metabox) { |
|
| 2939 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2940 | + $metabox["args"]["template_args"], true); |
|
| 2941 | + }, |
|
| 2942 | + $this->_current_screen->id, |
|
| 2943 | + 'side', |
|
| 2944 | + 'high', |
|
| 2945 | + $callback_args |
|
| 2946 | + ); |
|
| 2947 | + } |
|
| 2948 | + |
|
| 2949 | + //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2950 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2951 | + if (is_main_site()) { |
|
| 2952 | + add_meta_box( |
|
| 2953 | + 'espresso_global_message_settings', |
|
| 2954 | + __('Global Message Settings', 'event_espresso'), |
|
| 2955 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 2956 | + $this->_current_screen->id, |
|
| 2957 | + 'normal', |
|
| 2958 | + 'low', |
|
| 2959 | + array() |
|
| 2960 | + ); |
|
| 2961 | + } |
|
| 2962 | + |
|
| 2963 | + } |
|
| 2964 | + |
|
| 2965 | + |
|
| 2966 | + /** |
|
| 2967 | + * This generates the content for the global messages settings metabox. |
|
| 2968 | + * @return string |
|
| 2969 | + */ |
|
| 2970 | + public function global_messages_settings_metabox_content() |
|
| 2971 | + { |
|
| 2972 | + $form = $this->_generate_global_settings_form(); |
|
| 2973 | + echo $form->form_open( |
|
| 2974 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2975 | + 'POST' |
|
| 2976 | + ) |
|
| 2977 | + . $form->get_html() |
|
| 2978 | + . $form->form_close(); |
|
| 2979 | + } |
|
| 2980 | + |
|
| 2981 | + |
|
| 2982 | + /** |
|
| 2983 | + * This generates and returns the form object for the global messages settings. |
|
| 2984 | + * @return EE_Form_Section_Proper |
|
| 2985 | + */ |
|
| 2986 | + protected function _generate_global_settings_form() |
|
| 2987 | + { |
|
| 2988 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 2989 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 2990 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2991 | + |
|
| 2992 | + return new EE_Form_Section_Proper( |
|
| 2993 | + array( |
|
| 2994 | + 'name' => 'global_messages_settings', |
|
| 2995 | + 'html_id' => 'global_messages_settings', |
|
| 2996 | + 'html_class' => 'form-table', |
|
| 2997 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2998 | + 'subsections' => apply_filters( |
|
| 2999 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3000 | + array( |
|
| 3001 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3002 | + array( |
|
| 3003 | + true => __("On the same request", "event_espresso"), |
|
| 3004 | + false => __("On a separate request", "event_espresso") |
|
| 3005 | + ), |
|
| 3006 | + array( |
|
| 3007 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3008 | + 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 3009 | + 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3010 | + 'event_espresso'), |
|
| 3011 | + ) |
|
| 3012 | + ), |
|
| 3013 | + 'update_settings' => new EE_Submit_Input( |
|
| 3014 | + array( |
|
| 3015 | + 'default' => __('Update', 'event_espresso'), |
|
| 3016 | + 'html_label_text' => ' ' |
|
| 3017 | + ) |
|
| 3018 | + ) |
|
| 3019 | + ) |
|
| 3020 | + ) |
|
| 3021 | + ) |
|
| 3022 | + ); |
|
| 3023 | + } |
|
| 3024 | + |
|
| 3025 | + |
|
| 3026 | + /** |
|
| 3027 | + * This handles updating the global settings set on the admin page. |
|
| 3028 | + * @throws \EE_Error |
|
| 3029 | + */ |
|
| 3030 | + protected function _update_global_settings() |
|
| 3031 | + { |
|
| 3032 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3033 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3034 | + $form = $this->_generate_global_settings_form(); |
|
| 3035 | + if ($form->was_submitted()) { |
|
| 3036 | + $form->receive_form_submission(); |
|
| 3037 | + if ($form->is_valid()) { |
|
| 3038 | + $valid_data = $form->valid_data(); |
|
| 3039 | + foreach ($valid_data as $property => $value) { |
|
| 3040 | + $setter = 'set_' . $property; |
|
| 3041 | + if (method_exists($network_config, $setter)) { |
|
| 3042 | + $network_config->{$setter}($value); |
|
| 3043 | + } else if ( |
|
| 3044 | + property_exists($network_config, $property) |
|
| 3045 | + && $network_config->{$property} !== $value |
|
| 3046 | + ) { |
|
| 3047 | + $network_config->{$property} = $value; |
|
| 3048 | + } |
|
| 3049 | + } |
|
| 3050 | + //only update if the form submission was valid! |
|
| 3051 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3052 | + EE_Error::overwrite_success(); |
|
| 3053 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3054 | + } |
|
| 3055 | + } |
|
| 3056 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3057 | + } |
|
| 3058 | + |
|
| 3059 | + |
|
| 3060 | + /** |
|
| 3061 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3062 | + * |
|
| 3063 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3064 | + * |
|
| 3065 | + * @return string html formatted tabs |
|
| 3066 | + */ |
|
| 3067 | + protected function _get_mt_tabs($tab_array) |
|
| 3068 | + { |
|
| 3069 | + $tab_array = (array)$tab_array; |
|
| 3070 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3071 | + $tabs = ''; |
|
| 3072 | + |
|
| 3073 | + foreach ($tab_array as $tab) { |
|
| 3074 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3075 | + } |
|
| 3076 | + |
|
| 3077 | + return $tabs; |
|
| 3078 | + } |
|
| 3079 | + |
|
| 3080 | + |
|
| 3081 | + /** |
|
| 3082 | + * This prepares the content of the messenger meta box admin settings |
|
| 3083 | + * |
|
| 3084 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3085 | + * |
|
| 3086 | + * @return string html formatted content |
|
| 3087 | + */ |
|
| 3088 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3089 | + { |
|
| 3090 | + |
|
| 3091 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3092 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3093 | + |
|
| 3094 | + //is $messenger active? |
|
| 3095 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3096 | + |
|
| 3097 | + |
|
| 3098 | + if ( ! empty($fields)) { |
|
| 3099 | 3099 | |
| 3100 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3100 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3101 | 3101 | |
| 3102 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3103 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3104 | - $template_form_field[$field_id] = array( |
|
| 3105 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3106 | - 'label' => $fldprops['label'], |
|
| 3107 | - 'input' => $fldprops['field_type'], |
|
| 3108 | - 'type' => $fldprops['value_type'], |
|
| 3109 | - 'required' => $fldprops['required'], |
|
| 3110 | - 'validation' => $fldprops['validation'], |
|
| 3111 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3112 | - ? $existing_settings[$field_id] |
|
| 3113 | - : $fldprops['default'], |
|
| 3114 | - 'css_class' => '', |
|
| 3115 | - 'format' => $fldprops['format'] |
|
| 3116 | - ); |
|
| 3117 | - } |
|
| 3102 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3103 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3104 | + $template_form_field[$field_id] = array( |
|
| 3105 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3106 | + 'label' => $fldprops['label'], |
|
| 3107 | + 'input' => $fldprops['field_type'], |
|
| 3108 | + 'type' => $fldprops['value_type'], |
|
| 3109 | + 'required' => $fldprops['required'], |
|
| 3110 | + 'validation' => $fldprops['validation'], |
|
| 3111 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3112 | + ? $existing_settings[$field_id] |
|
| 3113 | + : $fldprops['default'], |
|
| 3114 | + 'css_class' => '', |
|
| 3115 | + 'format' => $fldprops['format'] |
|
| 3116 | + ); |
|
| 3117 | + } |
|
| 3118 | 3118 | |
| 3119 | 3119 | |
| 3120 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3121 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3122 | - : ''; |
|
| 3123 | - } |
|
| 3124 | - |
|
| 3125 | - //we also need some hidden fields |
|
| 3126 | - $settings_template_args['hidden_fields'] = array( |
|
| 3127 | - 'messenger_settings[messenger]' => array( |
|
| 3128 | - 'type' => 'hidden', |
|
| 3129 | - 'value' => $messenger->name |
|
| 3130 | - ), |
|
| 3131 | - 'type' => array( |
|
| 3132 | - 'type' => 'hidden', |
|
| 3133 | - 'value' => 'messenger' |
|
| 3134 | - ) |
|
| 3135 | - ); |
|
| 3136 | - |
|
| 3137 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3138 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3139 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3140 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3141 | - 'type' => 'hidden', |
|
| 3142 | - 'value' => $mt |
|
| 3143 | - ); |
|
| 3144 | - } |
|
| 3145 | - } |
|
| 3146 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3147 | - $settings_template_args['hidden_fields'], |
|
| 3148 | - 'array' |
|
| 3149 | - ); |
|
| 3150 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3151 | - |
|
| 3152 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3153 | - $settings_template_args['description'] = $messenger->description; |
|
| 3154 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3155 | - |
|
| 3156 | - |
|
| 3157 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3158 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3159 | - : ' hidden'; |
|
| 3160 | - |
|
| 3161 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3162 | - ? ' hidden' |
|
| 3163 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3164 | - |
|
| 3165 | - |
|
| 3166 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3167 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3168 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3169 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3170 | - $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3171 | - true); |
|
| 3172 | - |
|
| 3173 | - return $content; |
|
| 3174 | - } |
|
| 3175 | - |
|
| 3176 | - |
|
| 3177 | - /** |
|
| 3178 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3179 | - */ |
|
| 3180 | - public function activate_messenger_toggle() |
|
| 3181 | - { |
|
| 3182 | - $success = true; |
|
| 3183 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3184 | - //let's check that we have required data |
|
| 3185 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3186 | - EE_Error::add_error( |
|
| 3187 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3188 | - __FILE__, |
|
| 3189 | - __FUNCTION__, |
|
| 3190 | - __LINE__ |
|
| 3191 | - ); |
|
| 3192 | - $success = false; |
|
| 3193 | - } |
|
| 3194 | - |
|
| 3195 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3196 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3197 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3198 | - |
|
| 3199 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3200 | - |
|
| 3201 | - |
|
| 3202 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3203 | - EE_Error::add_error( |
|
| 3204 | - __( |
|
| 3205 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3206 | - 'event_espresso' |
|
| 3207 | - ), |
|
| 3208 | - __FILE__, |
|
| 3209 | - __FUNCTION__, |
|
| 3210 | - __LINE__ |
|
| 3211 | - ); |
|
| 3212 | - $success = false; |
|
| 3213 | - } |
|
| 3214 | - |
|
| 3215 | - //do check to verify we have a valid status. |
|
| 3216 | - $status = $this->_req_data['status']; |
|
| 3217 | - |
|
| 3218 | - if ($status != 'off' && $status != 'on') { |
|
| 3219 | - EE_Error::add_error( |
|
| 3220 | - sprintf( |
|
| 3221 | - __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3222 | - $this->_req_data['status'] |
|
| 3223 | - ), |
|
| 3224 | - __FILE__, |
|
| 3225 | - __FUNCTION__, |
|
| 3226 | - __LINE__ |
|
| 3227 | - ); |
|
| 3228 | - $success = false; |
|
| 3229 | - } |
|
| 3230 | - |
|
| 3231 | - if ($success) { |
|
| 3232 | - //made it here? Stop dawdling then!! |
|
| 3233 | - $success = $status == 'off' |
|
| 3234 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3235 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3236 | - } |
|
| 3237 | - |
|
| 3238 | - $this->_template_args['success'] = $success; |
|
| 3239 | - |
|
| 3240 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3241 | - $this->_return_json(); |
|
| 3242 | - |
|
| 3243 | - } |
|
| 3244 | - |
|
| 3245 | - |
|
| 3246 | - /** |
|
| 3247 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3248 | - * |
|
| 3249 | - */ |
|
| 3250 | - public function activate_mt_toggle() |
|
| 3251 | - { |
|
| 3252 | - $success = true; |
|
| 3253 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3254 | - |
|
| 3255 | - //let's make sure we have the necessary data |
|
| 3256 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3257 | - EE_Error::add_error( |
|
| 3258 | - __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3259 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3260 | - ); |
|
| 3261 | - $success = false; |
|
| 3262 | - } |
|
| 3263 | - |
|
| 3264 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3265 | - EE_Error::add_error( |
|
| 3266 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3267 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3268 | - ); |
|
| 3269 | - $success = false; |
|
| 3270 | - } |
|
| 3271 | - |
|
| 3272 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3273 | - EE_Error::add_error( |
|
| 3274 | - __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3275 | - 'event_espresso'), |
|
| 3276 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3277 | - ); |
|
| 3278 | - $success = false; |
|
| 3279 | - } |
|
| 3280 | - |
|
| 3281 | - |
|
| 3282 | - //do check to verify we have a valid status. |
|
| 3283 | - $status = $this->_req_data['status']; |
|
| 3284 | - |
|
| 3285 | - if ($status != 'activate' && $status != 'deactivate') { |
|
| 3286 | - EE_Error::add_error( |
|
| 3287 | - sprintf( |
|
| 3288 | - __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3289 | - $this->_req_data['status'] |
|
| 3290 | - ), |
|
| 3291 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3292 | - ); |
|
| 3293 | - $success = false; |
|
| 3294 | - } |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3298 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3299 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3300 | - |
|
| 3301 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3302 | - |
|
| 3303 | - if ($success) { |
|
| 3304 | - //made it here? um, what are you waiting for then? |
|
| 3305 | - $success = $status == 'deactivate' |
|
| 3306 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3307 | - $this->_req_data['message_type']) |
|
| 3308 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3309 | - $this->_req_data['message_type']); |
|
| 3310 | - } |
|
| 3311 | - |
|
| 3312 | - $this->_template_args['success'] = $success; |
|
| 3313 | - $this->_return_json(); |
|
| 3314 | - } |
|
| 3315 | - |
|
| 3316 | - |
|
| 3317 | - /** |
|
| 3318 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3319 | - * |
|
| 3320 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3321 | - * |
|
| 3322 | - * @return bool |
|
| 3323 | - */ |
|
| 3324 | - protected function _activate_messenger($messenger_name) |
|
| 3325 | - { |
|
| 3326 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3327 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3328 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3329 | - |
|
| 3330 | - //ensure is active |
|
| 3331 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3332 | - |
|
| 3333 | - //set response_data for reload |
|
| 3334 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3335 | - /** @var EE_message_type $message_type */ |
|
| 3336 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3337 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3338 | - $message_type_name) |
|
| 3339 | - && $message_type instanceof EE_message_type |
|
| 3340 | - ) { |
|
| 3341 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3342 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3343 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3344 | - } |
|
| 3345 | - } |
|
| 3346 | - } |
|
| 3347 | - |
|
| 3348 | - //add success message for activating messenger |
|
| 3349 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3350 | - |
|
| 3351 | - } |
|
| 3352 | - |
|
| 3353 | - |
|
| 3354 | - /** |
|
| 3355 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3356 | - * |
|
| 3357 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3358 | - * |
|
| 3359 | - * @return bool |
|
| 3360 | - */ |
|
| 3361 | - protected function _deactivate_messenger($messenger_name) |
|
| 3362 | - { |
|
| 3363 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3364 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3365 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3366 | - |
|
| 3367 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3368 | - } |
|
| 3369 | - |
|
| 3370 | - |
|
| 3371 | - /** |
|
| 3372 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3373 | - * |
|
| 3374 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3375 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3376 | - * |
|
| 3377 | - * @return bool |
|
| 3378 | - */ |
|
| 3379 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3380 | - { |
|
| 3381 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3382 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3383 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3384 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3385 | - |
|
| 3386 | - //ensure is active |
|
| 3387 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3388 | - |
|
| 3389 | - //set response for load |
|
| 3390 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3391 | - $message_type_name) |
|
| 3392 | - ) { |
|
| 3393 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3394 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3395 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3396 | - } |
|
| 3397 | - } |
|
| 3398 | - |
|
| 3399 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3400 | - $message_type_to_activate); |
|
| 3401 | - } |
|
| 3402 | - |
|
| 3403 | - |
|
| 3404 | - /** |
|
| 3405 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3406 | - * |
|
| 3407 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3408 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3409 | - * |
|
| 3410 | - * @return bool |
|
| 3411 | - */ |
|
| 3412 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3413 | - { |
|
| 3414 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3415 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3416 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3417 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3418 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3419 | - |
|
| 3420 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3421 | - $message_type_to_deactivate); |
|
| 3422 | - } |
|
| 3423 | - |
|
| 3424 | - |
|
| 3425 | - /** |
|
| 3426 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3427 | - */ |
|
| 3428 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3429 | - { |
|
| 3430 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 3431 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 3432 | - } |
|
| 3433 | - |
|
| 3434 | - |
|
| 3435 | - /** |
|
| 3436 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 3437 | - * |
|
| 3438 | - * @param EE_messenger $messenger |
|
| 3439 | - * @param EE_message_type|null $message_type |
|
| 3440 | - * |
|
| 3441 | - * @return bool |
|
| 3442 | - * @throws EE_Error |
|
| 3443 | - */ |
|
| 3444 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3445 | - $messenger, |
|
| 3446 | - EE_Message_Type $message_type = null |
|
| 3447 | - ) { |
|
| 3448 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3449 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3450 | - EE_Error::add_error( |
|
| 3451 | - __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3452 | - __FILE__, |
|
| 3453 | - __FUNCTION__, |
|
| 3454 | - __LINE__ |
|
| 3455 | - ); |
|
| 3120 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3121 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3122 | + : ''; |
|
| 3123 | + } |
|
| 3124 | + |
|
| 3125 | + //we also need some hidden fields |
|
| 3126 | + $settings_template_args['hidden_fields'] = array( |
|
| 3127 | + 'messenger_settings[messenger]' => array( |
|
| 3128 | + 'type' => 'hidden', |
|
| 3129 | + 'value' => $messenger->name |
|
| 3130 | + ), |
|
| 3131 | + 'type' => array( |
|
| 3132 | + 'type' => 'hidden', |
|
| 3133 | + 'value' => 'messenger' |
|
| 3134 | + ) |
|
| 3135 | + ); |
|
| 3136 | + |
|
| 3137 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3138 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3139 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3140 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3141 | + 'type' => 'hidden', |
|
| 3142 | + 'value' => $mt |
|
| 3143 | + ); |
|
| 3144 | + } |
|
| 3145 | + } |
|
| 3146 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3147 | + $settings_template_args['hidden_fields'], |
|
| 3148 | + 'array' |
|
| 3149 | + ); |
|
| 3150 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3151 | + |
|
| 3152 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3153 | + $settings_template_args['description'] = $messenger->description; |
|
| 3154 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3155 | + |
|
| 3156 | + |
|
| 3157 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3158 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3159 | + : ' hidden'; |
|
| 3160 | + |
|
| 3161 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3162 | + ? ' hidden' |
|
| 3163 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3164 | + |
|
| 3165 | + |
|
| 3166 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3167 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3168 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3169 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3170 | + $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3171 | + true); |
|
| 3172 | + |
|
| 3173 | + return $content; |
|
| 3174 | + } |
|
| 3175 | + |
|
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3179 | + */ |
|
| 3180 | + public function activate_messenger_toggle() |
|
| 3181 | + { |
|
| 3182 | + $success = true; |
|
| 3183 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3184 | + //let's check that we have required data |
|
| 3185 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3186 | + EE_Error::add_error( |
|
| 3187 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3188 | + __FILE__, |
|
| 3189 | + __FUNCTION__, |
|
| 3190 | + __LINE__ |
|
| 3191 | + ); |
|
| 3192 | + $success = false; |
|
| 3193 | + } |
|
| 3194 | + |
|
| 3195 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3196 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3197 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3198 | + |
|
| 3199 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3200 | + |
|
| 3201 | + |
|
| 3202 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3203 | + EE_Error::add_error( |
|
| 3204 | + __( |
|
| 3205 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3206 | + 'event_espresso' |
|
| 3207 | + ), |
|
| 3208 | + __FILE__, |
|
| 3209 | + __FUNCTION__, |
|
| 3210 | + __LINE__ |
|
| 3211 | + ); |
|
| 3212 | + $success = false; |
|
| 3213 | + } |
|
| 3214 | + |
|
| 3215 | + //do check to verify we have a valid status. |
|
| 3216 | + $status = $this->_req_data['status']; |
|
| 3217 | + |
|
| 3218 | + if ($status != 'off' && $status != 'on') { |
|
| 3219 | + EE_Error::add_error( |
|
| 3220 | + sprintf( |
|
| 3221 | + __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3222 | + $this->_req_data['status'] |
|
| 3223 | + ), |
|
| 3224 | + __FILE__, |
|
| 3225 | + __FUNCTION__, |
|
| 3226 | + __LINE__ |
|
| 3227 | + ); |
|
| 3228 | + $success = false; |
|
| 3229 | + } |
|
| 3230 | + |
|
| 3231 | + if ($success) { |
|
| 3232 | + //made it here? Stop dawdling then!! |
|
| 3233 | + $success = $status == 'off' |
|
| 3234 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3235 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3236 | + } |
|
| 3237 | + |
|
| 3238 | + $this->_template_args['success'] = $success; |
|
| 3239 | + |
|
| 3240 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3241 | + $this->_return_json(); |
|
| 3242 | + |
|
| 3243 | + } |
|
| 3244 | + |
|
| 3245 | + |
|
| 3246 | + /** |
|
| 3247 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3248 | + * |
|
| 3249 | + */ |
|
| 3250 | + public function activate_mt_toggle() |
|
| 3251 | + { |
|
| 3252 | + $success = true; |
|
| 3253 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3254 | + |
|
| 3255 | + //let's make sure we have the necessary data |
|
| 3256 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3257 | + EE_Error::add_error( |
|
| 3258 | + __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3259 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3260 | + ); |
|
| 3261 | + $success = false; |
|
| 3262 | + } |
|
| 3263 | + |
|
| 3264 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3265 | + EE_Error::add_error( |
|
| 3266 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3267 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3268 | + ); |
|
| 3269 | + $success = false; |
|
| 3270 | + } |
|
| 3271 | + |
|
| 3272 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3273 | + EE_Error::add_error( |
|
| 3274 | + __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3275 | + 'event_espresso'), |
|
| 3276 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3277 | + ); |
|
| 3278 | + $success = false; |
|
| 3279 | + } |
|
| 3280 | + |
|
| 3281 | + |
|
| 3282 | + //do check to verify we have a valid status. |
|
| 3283 | + $status = $this->_req_data['status']; |
|
| 3284 | + |
|
| 3285 | + if ($status != 'activate' && $status != 'deactivate') { |
|
| 3286 | + EE_Error::add_error( |
|
| 3287 | + sprintf( |
|
| 3288 | + __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3289 | + $this->_req_data['status'] |
|
| 3290 | + ), |
|
| 3291 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3292 | + ); |
|
| 3293 | + $success = false; |
|
| 3294 | + } |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3298 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3299 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3300 | + |
|
| 3301 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3302 | + |
|
| 3303 | + if ($success) { |
|
| 3304 | + //made it here? um, what are you waiting for then? |
|
| 3305 | + $success = $status == 'deactivate' |
|
| 3306 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3307 | + $this->_req_data['message_type']) |
|
| 3308 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3309 | + $this->_req_data['message_type']); |
|
| 3310 | + } |
|
| 3311 | + |
|
| 3312 | + $this->_template_args['success'] = $success; |
|
| 3313 | + $this->_return_json(); |
|
| 3314 | + } |
|
| 3315 | + |
|
| 3316 | + |
|
| 3317 | + /** |
|
| 3318 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3319 | + * |
|
| 3320 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3321 | + * |
|
| 3322 | + * @return bool |
|
| 3323 | + */ |
|
| 3324 | + protected function _activate_messenger($messenger_name) |
|
| 3325 | + { |
|
| 3326 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3327 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3328 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3329 | + |
|
| 3330 | + //ensure is active |
|
| 3331 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3332 | + |
|
| 3333 | + //set response_data for reload |
|
| 3334 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3335 | + /** @var EE_message_type $message_type */ |
|
| 3336 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3337 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3338 | + $message_type_name) |
|
| 3339 | + && $message_type instanceof EE_message_type |
|
| 3340 | + ) { |
|
| 3341 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3342 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3343 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3344 | + } |
|
| 3345 | + } |
|
| 3346 | + } |
|
| 3347 | + |
|
| 3348 | + //add success message for activating messenger |
|
| 3349 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3350 | + |
|
| 3351 | + } |
|
| 3352 | + |
|
| 3353 | + |
|
| 3354 | + /** |
|
| 3355 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3356 | + * |
|
| 3357 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3358 | + * |
|
| 3359 | + * @return bool |
|
| 3360 | + */ |
|
| 3361 | + protected function _deactivate_messenger($messenger_name) |
|
| 3362 | + { |
|
| 3363 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3364 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3365 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3366 | + |
|
| 3367 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3368 | + } |
|
| 3369 | + |
|
| 3370 | + |
|
| 3371 | + /** |
|
| 3372 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3373 | + * |
|
| 3374 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3375 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3376 | + * |
|
| 3377 | + * @return bool |
|
| 3378 | + */ |
|
| 3379 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3380 | + { |
|
| 3381 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3382 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3383 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3384 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3385 | + |
|
| 3386 | + //ensure is active |
|
| 3387 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3388 | + |
|
| 3389 | + //set response for load |
|
| 3390 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3391 | + $message_type_name) |
|
| 3392 | + ) { |
|
| 3393 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3394 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3395 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3396 | + } |
|
| 3397 | + } |
|
| 3398 | + |
|
| 3399 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3400 | + $message_type_to_activate); |
|
| 3401 | + } |
|
| 3402 | + |
|
| 3403 | + |
|
| 3404 | + /** |
|
| 3405 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3406 | + * |
|
| 3407 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3408 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3409 | + * |
|
| 3410 | + * @return bool |
|
| 3411 | + */ |
|
| 3412 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3413 | + { |
|
| 3414 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3415 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3416 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3417 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3418 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3419 | + |
|
| 3420 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3421 | + $message_type_to_deactivate); |
|
| 3422 | + } |
|
| 3423 | + |
|
| 3424 | + |
|
| 3425 | + /** |
|
| 3426 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3427 | + */ |
|
| 3428 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3429 | + { |
|
| 3430 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 3431 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 3432 | + } |
|
| 3433 | + |
|
| 3434 | + |
|
| 3435 | + /** |
|
| 3436 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 3437 | + * |
|
| 3438 | + * @param EE_messenger $messenger |
|
| 3439 | + * @param EE_message_type|null $message_type |
|
| 3440 | + * |
|
| 3441 | + * @return bool |
|
| 3442 | + * @throws EE_Error |
|
| 3443 | + */ |
|
| 3444 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3445 | + $messenger, |
|
| 3446 | + EE_Message_Type $message_type = null |
|
| 3447 | + ) { |
|
| 3448 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3449 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3450 | + EE_Error::add_error( |
|
| 3451 | + __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3452 | + __FILE__, |
|
| 3453 | + __FUNCTION__, |
|
| 3454 | + __LINE__ |
|
| 3455 | + ); |
|
| 3456 | 3456 | |
| 3457 | - return false; |
|
| 3458 | - } |
|
| 3459 | - //activated |
|
| 3460 | - if ($this->_template_args['data']['active_mts']) { |
|
| 3461 | - EE_Error::overwrite_success(); |
|
| 3462 | - //activated a message type with the messenger |
|
| 3463 | - if ($message_type instanceof EE_message_type) { |
|
| 3464 | - EE_Error::add_success( |
|
| 3465 | - sprintf( |
|
| 3466 | - __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3467 | - ucwords($message_type->label['singular']), |
|
| 3468 | - ucwords($messenger->label['singular']) |
|
| 3469 | - ) |
|
| 3470 | - ); |
|
| 3457 | + return false; |
|
| 3458 | + } |
|
| 3459 | + //activated |
|
| 3460 | + if ($this->_template_args['data']['active_mts']) { |
|
| 3461 | + EE_Error::overwrite_success(); |
|
| 3462 | + //activated a message type with the messenger |
|
| 3463 | + if ($message_type instanceof EE_message_type) { |
|
| 3464 | + EE_Error::add_success( |
|
| 3465 | + sprintf( |
|
| 3466 | + __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3467 | + ucwords($message_type->label['singular']), |
|
| 3468 | + ucwords($messenger->label['singular']) |
|
| 3469 | + ) |
|
| 3470 | + ); |
|
| 3471 | 3471 | |
| 3472 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3473 | - if ($message_type->name == 'invoice') { |
|
| 3474 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3475 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3476 | - if ($pm instanceof EE_Payment_Method) { |
|
| 3477 | - EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3478 | - 'event_espresso')); |
|
| 3479 | - } |
|
| 3480 | - } |
|
| 3481 | - //just toggles the entire messenger |
|
| 3482 | - } else { |
|
| 3483 | - EE_Error::add_success( |
|
| 3484 | - sprintf( |
|
| 3485 | - __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3486 | - ucwords($messenger->label['singular']) |
|
| 3487 | - ) |
|
| 3488 | - ); |
|
| 3489 | - } |
|
| 3472 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3473 | + if ($message_type->name == 'invoice') { |
|
| 3474 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3475 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3476 | + if ($pm instanceof EE_Payment_Method) { |
|
| 3477 | + EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3478 | + 'event_espresso')); |
|
| 3479 | + } |
|
| 3480 | + } |
|
| 3481 | + //just toggles the entire messenger |
|
| 3482 | + } else { |
|
| 3483 | + EE_Error::add_success( |
|
| 3484 | + sprintf( |
|
| 3485 | + __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3486 | + ucwords($messenger->label['singular']) |
|
| 3487 | + ) |
|
| 3488 | + ); |
|
| 3489 | + } |
|
| 3490 | 3490 | |
| 3491 | - return true; |
|
| 3491 | + return true; |
|
| 3492 | 3492 | |
| 3493 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3494 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3495 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 3496 | - } else { |
|
| 3497 | - if ( ! $messenger->get_default_message_types()) { |
|
| 3498 | - //messenger doesn't have any default message types so still a success. |
|
| 3499 | - EE_Error::add_success( |
|
| 3500 | - sprintf( |
|
| 3501 | - __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3502 | - ucwords($messenger->label['singular']) |
|
| 3503 | - ) |
|
| 3504 | - ); |
|
| 3493 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3494 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3495 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 3496 | + } else { |
|
| 3497 | + if ( ! $messenger->get_default_message_types()) { |
|
| 3498 | + //messenger doesn't have any default message types so still a success. |
|
| 3499 | + EE_Error::add_success( |
|
| 3500 | + sprintf( |
|
| 3501 | + __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3502 | + ucwords($messenger->label['singular']) |
|
| 3503 | + ) |
|
| 3504 | + ); |
|
| 3505 | 3505 | |
| 3506 | - return true; |
|
| 3507 | - } else { |
|
| 3508 | - EE_Error::add_error( |
|
| 3509 | - $message_type instanceof EE_message_type |
|
| 3510 | - ? sprintf( |
|
| 3511 | - __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3512 | - ucwords($message_type->label['singular']), |
|
| 3513 | - ucwords($messenger->label['singular']) |
|
| 3514 | - ) |
|
| 3515 | - : sprintf( |
|
| 3516 | - __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3517 | - ucwords($messenger->label['singular']) |
|
| 3518 | - ), |
|
| 3519 | - __FILE__, |
|
| 3520 | - __FUNCTION__, |
|
| 3521 | - __LINE__ |
|
| 3522 | - ); |
|
| 3506 | + return true; |
|
| 3507 | + } else { |
|
| 3508 | + EE_Error::add_error( |
|
| 3509 | + $message_type instanceof EE_message_type |
|
| 3510 | + ? sprintf( |
|
| 3511 | + __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3512 | + ucwords($message_type->label['singular']), |
|
| 3513 | + ucwords($messenger->label['singular']) |
|
| 3514 | + ) |
|
| 3515 | + : sprintf( |
|
| 3516 | + __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3517 | + ucwords($messenger->label['singular']) |
|
| 3518 | + ), |
|
| 3519 | + __FILE__, |
|
| 3520 | + __FUNCTION__, |
|
| 3521 | + __LINE__ |
|
| 3522 | + ); |
|
| 3523 | 3523 | |
| 3524 | - return false; |
|
| 3525 | - } |
|
| 3526 | - } |
|
| 3527 | - } |
|
| 3528 | - |
|
| 3529 | - |
|
| 3530 | - /** |
|
| 3531 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3532 | - * |
|
| 3533 | - * @param EE_messenger $messenger |
|
| 3534 | - * @param EE_message_type|null $message_type |
|
| 3535 | - * |
|
| 3536 | - * @return bool |
|
| 3537 | - */ |
|
| 3538 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3539 | - $messenger, |
|
| 3540 | - EE_message_type $message_type = null |
|
| 3541 | - ) { |
|
| 3542 | - EE_Error::overwrite_success(); |
|
| 3543 | - |
|
| 3544 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3545 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3546 | - EE_Error::add_error( |
|
| 3547 | - __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3548 | - __FILE__, |
|
| 3549 | - __FUNCTION__, |
|
| 3550 | - __LINE__ |
|
| 3551 | - ); |
|
| 3524 | + return false; |
|
| 3525 | + } |
|
| 3526 | + } |
|
| 3527 | + } |
|
| 3528 | + |
|
| 3529 | + |
|
| 3530 | + /** |
|
| 3531 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3532 | + * |
|
| 3533 | + * @param EE_messenger $messenger |
|
| 3534 | + * @param EE_message_type|null $message_type |
|
| 3535 | + * |
|
| 3536 | + * @return bool |
|
| 3537 | + */ |
|
| 3538 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3539 | + $messenger, |
|
| 3540 | + EE_message_type $message_type = null |
|
| 3541 | + ) { |
|
| 3542 | + EE_Error::overwrite_success(); |
|
| 3543 | + |
|
| 3544 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3545 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3546 | + EE_Error::add_error( |
|
| 3547 | + __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3548 | + __FILE__, |
|
| 3549 | + __FUNCTION__, |
|
| 3550 | + __LINE__ |
|
| 3551 | + ); |
|
| 3552 | 3552 | |
| 3553 | - return false; |
|
| 3554 | - } |
|
| 3555 | - |
|
| 3556 | - if ($message_type instanceof EE_message_type) { |
|
| 3557 | - $message_type_name = $message_type->name; |
|
| 3558 | - EE_Error::add_success( |
|
| 3559 | - sprintf( |
|
| 3560 | - __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3561 | - ucwords($message_type->label['singular']), |
|
| 3562 | - ucwords($messenger->label['singular']) |
|
| 3563 | - ) |
|
| 3564 | - ); |
|
| 3565 | - } else { |
|
| 3566 | - $message_type_name = ''; |
|
| 3567 | - EE_Error::add_success( |
|
| 3568 | - sprintf( |
|
| 3569 | - __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3570 | - ucwords($messenger->label['singular']) |
|
| 3571 | - ) |
|
| 3572 | - ); |
|
| 3573 | - } |
|
| 3574 | - |
|
| 3575 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3576 | - if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3577 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3578 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3579 | - if ($count_updated > 0) { |
|
| 3580 | - $msg = $message_type_name == 'invoice' |
|
| 3581 | - ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3582 | - 'event_espresso') |
|
| 3583 | - : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3584 | - 'event_espresso'); |
|
| 3585 | - EE_Error::add_attention($msg); |
|
| 3586 | - } |
|
| 3587 | - } |
|
| 3588 | - |
|
| 3589 | - return true; |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - |
|
| 3593 | - /** |
|
| 3594 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3595 | - */ |
|
| 3596 | - public function update_mt_form() |
|
| 3597 | - { |
|
| 3598 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3599 | - EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3600 | - __LINE__); |
|
| 3601 | - $this->_return_json(); |
|
| 3602 | - } |
|
| 3603 | - |
|
| 3604 | - $message_types = $this->get_installed_message_types(); |
|
| 3605 | - |
|
| 3606 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3607 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3608 | - |
|
| 3609 | - $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3610 | - $this->_template_args['success'] = true; |
|
| 3611 | - $this->_template_args['content'] = $content; |
|
| 3612 | - $this->_return_json(); |
|
| 3613 | - } |
|
| 3614 | - |
|
| 3615 | - |
|
| 3616 | - /** |
|
| 3617 | - * this handles saving the settings for a messenger or message type |
|
| 3618 | - * |
|
| 3619 | - */ |
|
| 3620 | - public function save_settings() |
|
| 3621 | - { |
|
| 3622 | - if ( ! isset($this->_req_data['type'])) { |
|
| 3623 | - EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3624 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3625 | - $this->_template_args['error'] = true; |
|
| 3626 | - $this->_return_json(); |
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - |
|
| 3630 | - if ($this->_req_data['type'] == 'messenger') { |
|
| 3631 | - $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3632 | - $messenger = $settings['messenger']; |
|
| 3633 | - //let's setup the settings data |
|
| 3634 | - foreach ($settings as $key => $value) { |
|
| 3635 | - switch ($key) { |
|
| 3636 | - case 'messenger' : |
|
| 3637 | - unset($settings['messenger']); |
|
| 3638 | - break; |
|
| 3639 | - case 'message_types' : |
|
| 3640 | - unset($settings['message_types']); |
|
| 3641 | - break; |
|
| 3642 | - default : |
|
| 3643 | - $settings[$key] = $value; |
|
| 3644 | - break; |
|
| 3645 | - } |
|
| 3646 | - } |
|
| 3647 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3648 | - } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3649 | - $settings = $this->_req_data['message_type_settings']; |
|
| 3650 | - $messenger = $settings['messenger']; |
|
| 3651 | - $message_type = $settings['message_type']; |
|
| 3553 | + return false; |
|
| 3554 | + } |
|
| 3555 | + |
|
| 3556 | + if ($message_type instanceof EE_message_type) { |
|
| 3557 | + $message_type_name = $message_type->name; |
|
| 3558 | + EE_Error::add_success( |
|
| 3559 | + sprintf( |
|
| 3560 | + __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3561 | + ucwords($message_type->label['singular']), |
|
| 3562 | + ucwords($messenger->label['singular']) |
|
| 3563 | + ) |
|
| 3564 | + ); |
|
| 3565 | + } else { |
|
| 3566 | + $message_type_name = ''; |
|
| 3567 | + EE_Error::add_success( |
|
| 3568 | + sprintf( |
|
| 3569 | + __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3570 | + ucwords($messenger->label['singular']) |
|
| 3571 | + ) |
|
| 3572 | + ); |
|
| 3573 | + } |
|
| 3574 | + |
|
| 3575 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3576 | + if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3577 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3578 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3579 | + if ($count_updated > 0) { |
|
| 3580 | + $msg = $message_type_name == 'invoice' |
|
| 3581 | + ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3582 | + 'event_espresso') |
|
| 3583 | + : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3584 | + 'event_espresso'); |
|
| 3585 | + EE_Error::add_attention($msg); |
|
| 3586 | + } |
|
| 3587 | + } |
|
| 3588 | + |
|
| 3589 | + return true; |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + |
|
| 3593 | + /** |
|
| 3594 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3595 | + */ |
|
| 3596 | + public function update_mt_form() |
|
| 3597 | + { |
|
| 3598 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3599 | + EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3600 | + __LINE__); |
|
| 3601 | + $this->_return_json(); |
|
| 3602 | + } |
|
| 3603 | + |
|
| 3604 | + $message_types = $this->get_installed_message_types(); |
|
| 3605 | + |
|
| 3606 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3607 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3608 | + |
|
| 3609 | + $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3610 | + $this->_template_args['success'] = true; |
|
| 3611 | + $this->_template_args['content'] = $content; |
|
| 3612 | + $this->_return_json(); |
|
| 3613 | + } |
|
| 3614 | + |
|
| 3615 | + |
|
| 3616 | + /** |
|
| 3617 | + * this handles saving the settings for a messenger or message type |
|
| 3618 | + * |
|
| 3619 | + */ |
|
| 3620 | + public function save_settings() |
|
| 3621 | + { |
|
| 3622 | + if ( ! isset($this->_req_data['type'])) { |
|
| 3623 | + EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3624 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3625 | + $this->_template_args['error'] = true; |
|
| 3626 | + $this->_return_json(); |
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + |
|
| 3630 | + if ($this->_req_data['type'] == 'messenger') { |
|
| 3631 | + $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3632 | + $messenger = $settings['messenger']; |
|
| 3633 | + //let's setup the settings data |
|
| 3634 | + foreach ($settings as $key => $value) { |
|
| 3635 | + switch ($key) { |
|
| 3636 | + case 'messenger' : |
|
| 3637 | + unset($settings['messenger']); |
|
| 3638 | + break; |
|
| 3639 | + case 'message_types' : |
|
| 3640 | + unset($settings['message_types']); |
|
| 3641 | + break; |
|
| 3642 | + default : |
|
| 3643 | + $settings[$key] = $value; |
|
| 3644 | + break; |
|
| 3645 | + } |
|
| 3646 | + } |
|
| 3647 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3648 | + } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3649 | + $settings = $this->_req_data['message_type_settings']; |
|
| 3650 | + $messenger = $settings['messenger']; |
|
| 3651 | + $message_type = $settings['message_type']; |
|
| 3652 | 3652 | |
| 3653 | - foreach ($settings as $key => $value) { |
|
| 3654 | - switch ($key) { |
|
| 3655 | - case 'messenger' : |
|
| 3656 | - unset($settings['messenger']); |
|
| 3657 | - break; |
|
| 3658 | - case 'message_type' : |
|
| 3659 | - unset($settings['message_type']); |
|
| 3660 | - break; |
|
| 3661 | - default : |
|
| 3662 | - $settings[$key] = $value; |
|
| 3663 | - break; |
|
| 3664 | - } |
|
| 3665 | - } |
|
| 3653 | + foreach ($settings as $key => $value) { |
|
| 3654 | + switch ($key) { |
|
| 3655 | + case 'messenger' : |
|
| 3656 | + unset($settings['messenger']); |
|
| 3657 | + break; |
|
| 3658 | + case 'message_type' : |
|
| 3659 | + unset($settings['message_type']); |
|
| 3660 | + break; |
|
| 3661 | + default : |
|
| 3662 | + $settings[$key] = $value; |
|
| 3663 | + break; |
|
| 3664 | + } |
|
| 3665 | + } |
|
| 3666 | 3666 | |
| 3667 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3668 | - } |
|
| 3669 | - |
|
| 3670 | - //okay we should have the data all setup. Now we just update! |
|
| 3671 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3672 | - |
|
| 3673 | - if ($success) { |
|
| 3674 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3675 | - } else { |
|
| 3676 | - EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3677 | - } |
|
| 3678 | - |
|
| 3679 | - $this->_template_args['success'] = $success; |
|
| 3680 | - $this->_return_json(); |
|
| 3681 | - } |
|
| 3682 | - |
|
| 3683 | - |
|
| 3684 | - |
|
| 3685 | - |
|
| 3686 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3687 | - |
|
| 3688 | - |
|
| 3689 | - /** |
|
| 3690 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3691 | - * However, this does not send immediately, it just queues for sending. |
|
| 3692 | - * |
|
| 3693 | - * @since 4.9.0 |
|
| 3694 | - */ |
|
| 3695 | - protected function _generate_now() |
|
| 3696 | - { |
|
| 3697 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3698 | - EED_Messages::generate_now($msg_ids); |
|
| 3699 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3700 | - } |
|
| 3701 | - |
|
| 3702 | - |
|
| 3703 | - /** |
|
| 3704 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3705 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3706 | - * |
|
| 3707 | - * @since 4.9.0 |
|
| 3708 | - * |
|
| 3709 | - */ |
|
| 3710 | - protected function _generate_and_send_now() |
|
| 3711 | - { |
|
| 3712 | - $this->_generate_now(); |
|
| 3713 | - $this->_send_now(); |
|
| 3714 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3715 | - } |
|
| 3716 | - |
|
| 3717 | - |
|
| 3718 | - /** |
|
| 3719 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3720 | - * |
|
| 3721 | - * @since 4.9.0 |
|
| 3722 | - */ |
|
| 3723 | - protected function _queue_for_resending() |
|
| 3724 | - { |
|
| 3725 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3726 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 3727 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3728 | - } |
|
| 3729 | - |
|
| 3730 | - |
|
| 3731 | - /** |
|
| 3732 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3733 | - * |
|
| 3734 | - * @since 4.9.0 |
|
| 3735 | - */ |
|
| 3736 | - protected function _send_now() |
|
| 3737 | - { |
|
| 3738 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3739 | - EED_Messages::send_now($msg_ids); |
|
| 3740 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3741 | - } |
|
| 3742 | - |
|
| 3743 | - |
|
| 3744 | - /** |
|
| 3745 | - * Deletes EE_messages for IDs in the request. |
|
| 3746 | - * |
|
| 3747 | - * @since 4.9.0 |
|
| 3748 | - */ |
|
| 3749 | - protected function _delete_ee_messages() |
|
| 3750 | - { |
|
| 3751 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3752 | - $deleted_count = 0; |
|
| 3753 | - foreach ($msg_ids as $msg_id) { |
|
| 3754 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3755 | - $deleted_count++; |
|
| 3756 | - } |
|
| 3757 | - } |
|
| 3758 | - if ($deleted_count) { |
|
| 3759 | - $this->_redirect_after_action( |
|
| 3760 | - true, |
|
| 3761 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3762 | - __('deleted', 'event_espresso') |
|
| 3763 | - ); |
|
| 3764 | - } else { |
|
| 3765 | - EE_Error::add_error( |
|
| 3766 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3767 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3768 | - ); |
|
| 3769 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3770 | - } |
|
| 3771 | - } |
|
| 3772 | - |
|
| 3773 | - |
|
| 3774 | - /** |
|
| 3775 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3776 | - * @since 4.9.0 |
|
| 3777 | - * @return array |
|
| 3778 | - */ |
|
| 3779 | - protected function _get_msg_ids_from_request() |
|
| 3780 | - { |
|
| 3781 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3782 | - return array(); |
|
| 3783 | - } |
|
| 3784 | - |
|
| 3785 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3786 | - } |
|
| 3667 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3668 | + } |
|
| 3669 | + |
|
| 3670 | + //okay we should have the data all setup. Now we just update! |
|
| 3671 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3672 | + |
|
| 3673 | + if ($success) { |
|
| 3674 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3675 | + } else { |
|
| 3676 | + EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3677 | + } |
|
| 3678 | + |
|
| 3679 | + $this->_template_args['success'] = $success; |
|
| 3680 | + $this->_return_json(); |
|
| 3681 | + } |
|
| 3682 | + |
|
| 3683 | + |
|
| 3684 | + |
|
| 3685 | + |
|
| 3686 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3687 | + |
|
| 3688 | + |
|
| 3689 | + /** |
|
| 3690 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3691 | + * However, this does not send immediately, it just queues for sending. |
|
| 3692 | + * |
|
| 3693 | + * @since 4.9.0 |
|
| 3694 | + */ |
|
| 3695 | + protected function _generate_now() |
|
| 3696 | + { |
|
| 3697 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3698 | + EED_Messages::generate_now($msg_ids); |
|
| 3699 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3700 | + } |
|
| 3701 | + |
|
| 3702 | + |
|
| 3703 | + /** |
|
| 3704 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3705 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3706 | + * |
|
| 3707 | + * @since 4.9.0 |
|
| 3708 | + * |
|
| 3709 | + */ |
|
| 3710 | + protected function _generate_and_send_now() |
|
| 3711 | + { |
|
| 3712 | + $this->_generate_now(); |
|
| 3713 | + $this->_send_now(); |
|
| 3714 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3715 | + } |
|
| 3716 | + |
|
| 3717 | + |
|
| 3718 | + /** |
|
| 3719 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3720 | + * |
|
| 3721 | + * @since 4.9.0 |
|
| 3722 | + */ |
|
| 3723 | + protected function _queue_for_resending() |
|
| 3724 | + { |
|
| 3725 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3726 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 3727 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3728 | + } |
|
| 3729 | + |
|
| 3730 | + |
|
| 3731 | + /** |
|
| 3732 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3733 | + * |
|
| 3734 | + * @since 4.9.0 |
|
| 3735 | + */ |
|
| 3736 | + protected function _send_now() |
|
| 3737 | + { |
|
| 3738 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3739 | + EED_Messages::send_now($msg_ids); |
|
| 3740 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3741 | + } |
|
| 3742 | + |
|
| 3743 | + |
|
| 3744 | + /** |
|
| 3745 | + * Deletes EE_messages for IDs in the request. |
|
| 3746 | + * |
|
| 3747 | + * @since 4.9.0 |
|
| 3748 | + */ |
|
| 3749 | + protected function _delete_ee_messages() |
|
| 3750 | + { |
|
| 3751 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3752 | + $deleted_count = 0; |
|
| 3753 | + foreach ($msg_ids as $msg_id) { |
|
| 3754 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3755 | + $deleted_count++; |
|
| 3756 | + } |
|
| 3757 | + } |
|
| 3758 | + if ($deleted_count) { |
|
| 3759 | + $this->_redirect_after_action( |
|
| 3760 | + true, |
|
| 3761 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3762 | + __('deleted', 'event_espresso') |
|
| 3763 | + ); |
|
| 3764 | + } else { |
|
| 3765 | + EE_Error::add_error( |
|
| 3766 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3767 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3768 | + ); |
|
| 3769 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3770 | + } |
|
| 3771 | + } |
|
| 3772 | + |
|
| 3773 | + |
|
| 3774 | + /** |
|
| 3775 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3776 | + * @since 4.9.0 |
|
| 3777 | + * @return array |
|
| 3778 | + */ |
|
| 3779 | + protected function _get_msg_ids_from_request() |
|
| 3780 | + { |
|
| 3781 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3782 | + return array(); |
|
| 3783 | + } |
|
| 3784 | + |
|
| 3785 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3786 | + } |
|
| 3787 | 3787 | |
| 3788 | 3788 | |
| 3789 | 3789 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 93 | 93 | $this->_load_message_resource_manager(); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | array('none_selected' => __('Show All Messengers', 'event_espresso')), |
| 220 | 220 | $messenger_options |
| 221 | 221 | ); |
| 222 | - $input = new EE_Select_Input( |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | 223 | $messenger_options, |
| 224 | 224 | array( |
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by', |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | array('none_selected' => __('Show All Message Types', 'event_espresso')), |
| 258 | 258 | $message_type_options |
| 259 | 259 | ); |
| 260 | - $input = new EE_Select_Input( |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | 261 | $message_type_options, |
| 262 | 262 | array( |
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | array('none_selected' => __('Show all Contexts', 'event_espresso')), |
| 296 | 296 | $context_options |
| 297 | 297 | ); |
| 298 | - $input = new EE_Select_Input( |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | 299 | $context_options, |
| 300 | 300 | array( |
| 301 | 301 | 'html_name' => 'ee_context_filter_by', |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab() |
| 678 | 678 | { |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab() |
| 684 | 684 | { |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab() |
| 690 | 690 | { |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab() |
| 696 | 696 | { |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab() |
| 702 | 702 | { |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab() |
| 708 | 708 | { |
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 709 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso').'" />'; |
|
| 711 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso').'" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso').'" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso').'" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso').'" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | 720 | $args); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block |
||
| 725 | 725 | { |
| 726 | 726 | $this->_set_shortcodes(); |
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes; |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | 729 | $args); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab() |
| 734 | 734 | { |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab() |
| 740 | 740 | { |
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso').'" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso').'" />'; |
|
| 745 | 745 | $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
| 746 | 746 | $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles() |
| 752 | 752 | { |
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | 754 | wp_enqueue_style('espresso_ee_msg'); |
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 757 | 757 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 759 | 759 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes(); |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | 791 | __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
| 792 | 792 | 'event_espresso'), |
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'], |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
| 797 | 797 | 'event_espresso'); |
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), |
|
| 800 | 800 | EVENT_ESPRESSO_VERSION); |
| 801 | 801 | |
| 802 | 802 | wp_enqueue_script('ee_admin_js'); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings() |
| 829 | 829 | { |
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), |
|
| 831 | 831 | EVENT_ESPRESSO_VERSION); |
| 832 | 832 | wp_enqueue_style('ee-text-links'); |
| 833 | 833 | wp_enqueue_style('ee-message-settings'); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | } |
| 894 | 894 | $status_bulk_actions = $common_bulk_actions; |
| 895 | 895 | //unset bulk actions not applying to status |
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 896 | + if ( ! empty($status_bulk_actions)) { |
|
| 897 | 897 | switch ($status) { |
| 898 | 898 | case EEM_Message::status_idle: |
| 899 | 899 | case EEM_Message::status_resend: |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 921 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
| 945 | 945 | $this->_template_args['per_column'] = 6; |
| 946 | 946 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>'; |
|
| 948 | 948 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 949 | 949 | } |
| 950 | 950 | |
@@ -968,37 +968,37 @@ discard block |
||
| 968 | 968 | /** @type array $status_items status legend setup */ |
| 969 | 969 | $status_items = array( |
| 970 | 970 | 'sent_status' => array( |
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 972 | 972 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 973 | 973 | ), |
| 974 | 974 | 'idle_status' => array( |
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 976 | 976 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 977 | 977 | ), |
| 978 | 978 | 'failed_status' => array( |
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 980 | 980 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 981 | 981 | ), |
| 982 | 982 | 'messenger_executing_status' => array( |
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 984 | 984 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 985 | 985 | ), |
| 986 | 986 | 'resend_status' => array( |
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 988 | 988 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 989 | 989 | ), |
| 990 | 990 | 'incomplete_status' => array( |
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 993 | 993 | ), |
| 994 | 994 | 'retry_status' => array( |
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 996 | 996 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 997 | 997 | ) |
| 998 | 998 | ); |
| 999 | 999 | if (EEM_Message::debug()) { |
| 1000 | 1000 | $status_items['debug_only_status'] = array( |
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1002 | 1002 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1003 | 1003 | ); |
| 1004 | 1004 | } |
@@ -1010,10 +1010,10 @@ discard block |
||
| 1010 | 1010 | protected function _custom_mtps_preview() |
| 1011 | 1011 | { |
| 1012 | 1012 | $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso').'" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso').'</strong>'; |
|
| 1017 | 1017 | $this->display_admin_caf_preview_page('custom_message_types', false); |
| 1018 | 1018 | } |
| 1019 | 1019 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1262 | 1262 | $continue = false; |
| 1263 | 1263 | if (isset($extra_array['shortcodes_required'])) { |
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1264 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | 1265 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1266 | 1266 | $continue = true; |
| 1267 | 1267 | } |
@@ -1271,9 +1271,9 @@ discard block |
||
| 1271 | 1271 | } |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1274 | + $field_id = $reference_field.'-'.$extra_field.'-content'; |
|
| 1275 | 1275 | $template_form_fields[$field_id] = $extra_array; |
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']'; |
|
| 1277 | 1277 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | is_array($validators[$extra_field]) |
| 1284 | 1284 | && isset($validators[$extra_field]['msg']) |
| 1285 | 1285 | ) |
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1286 | + ? 'validate-error '.$css_class |
|
| 1287 | 1287 | : $css_class; |
| 1288 | 1288 | |
| 1289 | 1289 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
@@ -1311,11 +1311,11 @@ discard block |
||
| 1311 | 1311 | |
| 1312 | 1312 | }/**/ |
| 1313 | 1313 | } |
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1314 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1316 | 1316 | |
| 1317 | 1317 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1318 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1319 | 1319 | 'label' => null, |
| 1320 | 1320 | 'input' => 'hidden', |
| 1321 | 1321 | 'type' => 'int', |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | |
| 1330 | 1330 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1331 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1332 | 1332 | 'label' => null, |
| 1333 | 1333 | 'input' => 'hidden', |
| 1334 | 1334 | 'type' => 'string', |
@@ -1342,9 +1342,9 @@ discard block |
||
| 1342 | 1342 | } |
| 1343 | 1343 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1344 | 1344 | } else { |
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1345 | + $field_id = $template_field.'-content'; |
|
| 1346 | 1346 | $template_form_fields[$field_id] = $field_setup_array; |
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1348 | 1348 | $message_template = isset($message_templates[$context][$template_field]) |
| 1349 | 1349 | ? $message_templates[$context][$template_field] |
| 1350 | 1350 | : null; |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1366 | 1366 | && in_array($template_field, $v_fields) |
| 1367 | 1367 | && isset($validators[$template_field]['msg']) |
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1368 | + ? 'validate-error '.$css_class |
|
| 1369 | 1369 | : $css_class; |
| 1370 | 1370 | |
| 1371 | 1371 | //shortcode selector |
@@ -1376,12 +1376,12 @@ discard block |
||
| 1376 | 1376 | |
| 1377 | 1377 | //k took care of content field(s) now let's take care of others. |
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1381 | 1381 | |
| 1382 | 1382 | //foreach template field there are actually two form fields created |
| 1383 | 1383 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1384 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1385 | 1385 | 'label' => null, |
| 1386 | 1386 | 'input' => 'hidden', |
| 1387 | 1387 | 'type' => 'int', |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | ); |
| 1395 | 1395 | |
| 1396 | 1396 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1397 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1398 | 1398 | 'label' => null, |
| 1399 | 1399 | 'input' => 'hidden', |
| 1400 | 1400 | 'type' => 'string', |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | 'format' => '%d', |
| 1513 | 1513 | 'db-col' => 'MTP_deleted' |
| 1514 | 1514 | ); |
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | 1516 | 'name' => 'MTP_user_id', |
| 1517 | 1517 | 'label' => __('Author', 'event_espresso'), |
| 1518 | 1518 | 'input' => 'hidden', |
@@ -1531,17 +1531,17 @@ discard block |
||
| 1531 | 1531 | 'value' => $action |
| 1532 | 1532 | ); |
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | 1535 | 'name' => 'id', |
| 1536 | 1536 | 'input' => 'hidden', |
| 1537 | 1537 | 'type' => 'int', |
| 1538 | 1538 | 'value' => $GRP_ID |
| 1539 | 1539 | ); |
| 1540 | 1540 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1541 | - 'name' => $action . '_nonce', |
|
| 1541 | + 'name' => $action.'_nonce', |
|
| 1542 | 1542 | 'input' => 'hidden', |
| 1543 | 1543 | 'type' => 'string', |
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1544 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1545 | 1545 | ); |
| 1546 | 1546 | |
| 1547 | 1547 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | ); |
| 1574 | 1574 | |
| 1575 | 1575 | //add preview button |
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | 1577 | array( |
| 1578 | 1578 | 'message_type' => $message_template_group->message_type(), |
| 1579 | 1579 | 'messenger' => $message_template_group->messenger(), |
@@ -1583,8 +1583,8 @@ discard block |
||
| 1583 | 1583 | ), |
| 1584 | 1584 | $this->_admin_base_url |
| 1585 | 1585 | ); |
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1586 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', |
|
| 1587 | + 'event_espresso').'</a>'; |
|
| 1588 | 1588 | |
| 1589 | 1589 | |
| 1590 | 1590 | //setup context switcher |
@@ -1613,7 +1613,7 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1615 | 1615 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | 1617 | |
| 1618 | 1618 | //send along EE_Message_Template_Group object for further template use. |
| 1619 | 1619 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | |
| 1649 | 1649 | public function _add_form_element_before() |
| 1650 | 1650 | { |
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1651 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">'; |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | public function _add_form_element_after() |
@@ -1843,14 +1843,14 @@ discard block |
||
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | //let's add a button to go back to the edit view |
| 1846 | - $query_args = array( |
|
| 1846 | + $query_args = array( |
|
| 1847 | 1847 | 'id' => $this->_req_data['GRP_ID'], |
| 1848 | 1848 | 'context' => $this->_req_data['context'], |
| 1849 | 1849 | 'action' => 'edit_message_template' |
| 1850 | 1850 | ); |
| 1851 | 1851 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1852 | + $preview_button = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', |
|
| 1853 | + 'event_espresso').'</a>'; |
|
| 1854 | 1854 | $message_types = $this->get_installed_message_types(); |
| 1855 | 1855 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 1856 | 1856 | $active_messenger_label = $active_messenger instanceof EE_messenger |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | ); |
| 1865 | 1865 | //setup display of preview. |
| 1866 | 1866 | $this->_admin_page_title = $preview_title; |
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 1868 | 1868 | $this->_template_args['data']['force_json'] = true; |
| 1869 | 1869 | |
| 1870 | 1870 | return ''; |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | //setup variation select values for the currently selected template. |
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | 1950 | $this->_message_template_group->messenger(), |
| 1951 | 1951 | $this->_message_template_group->message_type() |
| 1952 | 1952 | ); |
@@ -1960,12 +1960,12 @@ discard block |
||
| 1960 | 1960 | |
| 1961 | 1961 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 1962 | 1962 | |
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | 1964 | 'MTP_template_pack', |
| 1965 | 1965 | $tp_select_values, |
| 1966 | 1966 | $this->_message_template_group->get_template_pack_name() |
| 1967 | 1967 | ); |
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | 1969 | 'MTP_template_variation', |
| 1970 | 1970 | $variations_select_values, |
| 1971 | 1971 | $this->_message_template_group->get_template_pack_variation() |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 1976 | 1976 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 1977 | 1977 | |
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | 1979 | |
| 1980 | 1980 | EEH_Template::display_template($template, $template_args); |
| 1981 | 1981 | } |
@@ -2004,7 +2004,7 @@ discard block |
||
| 2004 | 2004 | if ( ! empty($fields)) { |
| 2005 | 2005 | //yup there be fields |
| 2006 | 2006 | foreach ($fields as $field => $config) { |
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2007 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2008 | 2008 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2009 | 2009 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2010 | 2010 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2019,7 +2019,7 @@ discard block |
||
| 2019 | 2019 | : $fix; |
| 2020 | 2020 | |
| 2021 | 2021 | $template_form_fields[$field_id] = array( |
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2022 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2023 | 2023 | 'label' => $config['label'], |
| 2024 | 2024 | 'input' => $config['input'], |
| 2025 | 2025 | 'type' => $config['type'], |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | //and button |
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2052 | + $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; |
|
| 2053 | 2053 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
| 2054 | 2054 | $test_settings_html .= $this->get_action_link_or_button( |
| 2055 | 2055 | 'reset_to_default', |
@@ -2080,7 +2080,7 @@ discard block |
||
| 2080 | 2080 | 'linked_input_id' => $linked_input_id |
| 2081 | 2081 | ); |
| 2082 | 2082 | |
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2084 | 2084 | $template_args, true); |
| 2085 | 2085 | } |
| 2086 | 2086 | |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2099 | 2099 | //now let's set the content depending on the status of the shortcodes array |
| 2100 | 2100 | if (empty($shortcodes)) { |
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2101 | + $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2102 | 2102 | echo $content; |
| 2103 | 2103 | } else { |
| 2104 | 2104 | //$alt = 0; |
@@ -2215,7 +2215,7 @@ discard block |
||
| 2215 | 2215 | <?php |
| 2216 | 2216 | } |
| 2217 | 2217 | //setup nonce_url |
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2218 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2219 | 2219 | ?> |
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | : ''; |
| 2314 | 2314 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2315 | 2315 | |
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : ''; |
|
| 2317 | 2317 | $item_desc .= 'Message Template'; |
| 2318 | 2318 | $query_args = array(); |
| 2319 | 2319 | $edit_array = array(); |
@@ -2688,8 +2688,8 @@ discard block |
||
| 2688 | 2688 | */ |
| 2689 | 2689 | protected function _learn_more_about_message_templates_link() |
| 2690 | 2690 | { |
| 2691 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2692 | - 'event_espresso') . '</a>'; |
|
| 2691 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', |
|
| 2692 | + 'event_espresso').'</a>'; |
|
| 2693 | 2693 | } |
| 2694 | 2694 | |
| 2695 | 2695 | |
@@ -2765,10 +2765,10 @@ discard block |
||
| 2765 | 2765 | |
| 2766 | 2766 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 2767 | 2767 | 'label' => ucwords($message_type->label['singular']), |
| 2768 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2769 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2770 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2771 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2768 | + 'class' => 'message-type-'.$a_or_i, |
|
| 2769 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 2770 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 2771 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 2772 | 2772 | 'title' => $a_or_i == 'active' |
| 2773 | 2773 | ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 2774 | 2774 | : __('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -2804,9 +2804,9 @@ discard block |
||
| 2804 | 2804 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 2805 | 2805 | |
| 2806 | 2806 | foreach ($fields as $fldname => $fldprops) { |
| 2807 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2807 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 2808 | 2808 | $template_form_field[$field_id] = array( |
| 2809 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2809 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 2810 | 2810 | 'label' => $fldprops['label'], |
| 2811 | 2811 | 'input' => $fldprops['field_type'], |
| 2812 | 2812 | 'type' => $fldprops['value_type'], |
@@ -2847,7 +2847,7 @@ discard block |
||
| 2847 | 2847 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
| 2848 | 2848 | |
| 2849 | 2849 | |
| 2850 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2850 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 2851 | 2851 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 2852 | 2852 | |
| 2853 | 2853 | return $content; |
@@ -2877,11 +2877,11 @@ discard block |
||
| 2877 | 2877 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
| 2878 | 2878 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 2879 | 2879 | : ''; |
| 2880 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2880 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 2881 | 2881 | __('%s Settings', 'event_espresso'), |
| 2882 | 2882 | $tab_array['label'] |
| 2883 | 2883 | ); |
| 2884 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2884 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 2885 | 2885 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2886 | 2886 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2887 | 2887 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2895,8 +2895,8 @@ discard block |
||
| 2895 | 2895 | // message type meta boxes |
| 2896 | 2896 | // (which is really just the inactive container for each messenger |
| 2897 | 2897 | // showing inactive message types for that messenger) |
| 2898 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2898 | + $mt_boxes[$messenger.'_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 2900 | 2900 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2901 | 2901 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2902 | 2902 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2912,14 +2912,14 @@ discard block |
||
| 2912 | 2912 | |
| 2913 | 2913 | |
| 2914 | 2914 | //register messenger metaboxes |
| 2915 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2915 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2916 | 2916 | foreach ($m_boxes as $box => $label) { |
| 2917 | 2917 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 2918 | 2918 | $msgr = str_replace('_a_box', '', $box); |
| 2919 | 2919 | add_meta_box( |
| 2920 | - 'espresso_' . $msgr . '_settings', |
|
| 2920 | + 'espresso_'.$msgr.'_settings', |
|
| 2921 | 2921 | $label, |
| 2922 | - function ($post, $metabox) { |
|
| 2922 | + function($post, $metabox) { |
|
| 2923 | 2923 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2924 | 2924 | $metabox["args"]["template_args"], true); |
| 2925 | 2925 | }, |
@@ -2931,17 +2931,17 @@ discard block |
||
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | //register message type metaboxes |
| 2934 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2934 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2935 | 2935 | foreach ($mt_boxes as $box => $label) { |
| 2936 | 2936 | $callback_args = array( |
| 2937 | 2937 | 'template_path' => $mt_template_path, |
| 2938 | 2938 | 'template_args' => $mt_template_args[$box] |
| 2939 | 2939 | ); |
| 2940 | - $mt = str_replace('_i_box', '', $box); |
|
| 2940 | + $mt = str_replace('_i_box', '', $box); |
|
| 2941 | 2941 | add_meta_box( |
| 2942 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2942 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 2943 | 2943 | $label, |
| 2944 | - function ($post, $metabox) { |
|
| 2944 | + function($post, $metabox) { |
|
| 2945 | 2945 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2946 | 2946 | $metabox["args"]["template_args"], true); |
| 2947 | 2947 | }, |
@@ -3043,7 +3043,7 @@ discard block |
||
| 3043 | 3043 | if ($form->is_valid()) { |
| 3044 | 3044 | $valid_data = $form->valid_data(); |
| 3045 | 3045 | foreach ($valid_data as $property => $value) { |
| 3046 | - $setter = 'set_' . $property; |
|
| 3046 | + $setter = 'set_'.$property; |
|
| 3047 | 3047 | if (method_exists($network_config, $setter)) { |
| 3048 | 3048 | $network_config->{$setter}($value); |
| 3049 | 3049 | } else if ( |
@@ -3072,8 +3072,8 @@ discard block |
||
| 3072 | 3072 | */ |
| 3073 | 3073 | protected function _get_mt_tabs($tab_array) |
| 3074 | 3074 | { |
| 3075 | - $tab_array = (array)$tab_array; |
|
| 3076 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3075 | + $tab_array = (array) $tab_array; |
|
| 3076 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3077 | 3077 | $tabs = ''; |
| 3078 | 3078 | |
| 3079 | 3079 | foreach ($tab_array as $tab) { |
@@ -3106,9 +3106,9 @@ discard block |
||
| 3106 | 3106 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3107 | 3107 | |
| 3108 | 3108 | foreach ($fields as $fldname => $fldprops) { |
| 3109 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3109 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3110 | 3110 | $template_form_field[$field_id] = array( |
| 3111 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3111 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3112 | 3112 | 'label' => $fldprops['label'], |
| 3113 | 3113 | 'input' => $fldprops['field_type'], |
| 3114 | 3114 | 'type' => $fldprops['value_type'], |
@@ -3143,7 +3143,7 @@ discard block |
||
| 3143 | 3143 | //make sure any active message types that are existing are included in the hidden fields |
| 3144 | 3144 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3145 | 3145 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3146 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3146 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3147 | 3147 | 'type' => 'hidden', |
| 3148 | 3148 | 'value' => $mt |
| 3149 | 3149 | ); |
@@ -3153,7 +3153,7 @@ discard block |
||
| 3153 | 3153 | $settings_template_args['hidden_fields'], |
| 3154 | 3154 | 'array' |
| 3155 | 3155 | ); |
| 3156 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3156 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3157 | 3157 | |
| 3158 | 3158 | $settings_template_args['messenger'] = $messenger->name; |
| 3159 | 3159 | $settings_template_args['description'] = $messenger->description; |
@@ -3170,9 +3170,9 @@ discard block |
||
| 3170 | 3170 | |
| 3171 | 3171 | |
| 3172 | 3172 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3173 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3173 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3174 | 3174 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3175 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3175 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3176 | 3176 | $content = EEH_Template::display_template($template, $settings_template_args, |
| 3177 | 3177 | true); |
| 3178 | 3178 | |
@@ -3200,7 +3200,7 @@ discard block |
||
| 3200 | 3200 | |
| 3201 | 3201 | //do a nonce check here since we're not arriving via a normal route |
| 3202 | 3202 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
| 3203 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3203 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3204 | 3204 | |
| 3205 | 3205 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3206 | 3206 | |
@@ -3302,7 +3302,7 @@ discard block |
||
| 3302 | 3302 | |
| 3303 | 3303 | //do a nonce check here since we're not arriving via a normal route |
| 3304 | 3304 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3305 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3305 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3306 | 3306 | |
| 3307 | 3307 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3308 | 3308 | |