@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - 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 | - ); ?> |
|
| 52 | + 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 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 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.4.0'); |
|
| 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 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.057'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.057'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -75,6 +75,9 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | + /** |
|
| 79 | + * @param string[] $valid_shortcodes |
|
| 80 | + */ |
|
| 78 | 81 | public function parse_attendee_list_template( |
| 79 | 82 | $template, |
| 80 | 83 | EE_Registration $registration, |
@@ -86,6 +89,9 @@ discard block |
||
| 86 | 89 | return $this->_parse_message_template(); |
| 87 | 90 | } |
| 88 | 91 | |
| 92 | + /** |
|
| 93 | + * @param string[] $valid_shortcodes |
|
| 94 | + */ |
|
| 89 | 95 | public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
| 90 | 96 | { |
| 91 | 97 | $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
@@ -94,6 +100,9 @@ discard block |
||
| 94 | 100 | } |
| 95 | 101 | |
| 96 | 102 | |
| 103 | + /** |
|
| 104 | + * @param string[] $valid_shortcodes |
|
| 105 | + */ |
|
| 97 | 106 | public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
| 98 | 107 | { |
| 99 | 108 | $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
@@ -102,6 +111,9 @@ discard block |
||
| 102 | 111 | } |
| 103 | 112 | |
| 104 | 113 | |
| 114 | + /** |
|
| 115 | + * @param string[] $valid_shortcodes |
|
| 116 | + */ |
|
| 105 | 117 | public function parse_line_item_list_template( |
| 106 | 118 | $template, |
| 107 | 119 | EE_Line_Item $line_item, |
@@ -114,6 +126,9 @@ discard block |
||
| 114 | 126 | } |
| 115 | 127 | |
| 116 | 128 | |
| 129 | + /** |
|
| 130 | + * @param string[] $valid_shortcodes |
|
| 131 | + */ |
|
| 117 | 132 | public function parse_payment_list_template( |
| 118 | 133 | $template, |
| 119 | 134 | EE_Payment $payment_item, |
@@ -126,6 +141,9 @@ discard block |
||
| 126 | 141 | } |
| 127 | 142 | |
| 128 | 143 | |
| 144 | + /** |
|
| 145 | + * @param string[] $valid_shortcodes |
|
| 146 | + */ |
|
| 129 | 147 | public function parse_datetime_list_template( |
| 130 | 148 | $template, |
| 131 | 149 | EE_Datetime $datetime, |
@@ -13,290 +13,290 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * holds the template |
|
| 18 | - * |
|
| 19 | - * @access private |
|
| 20 | - * @var mixed (string|array) |
|
| 21 | - */ |
|
| 22 | - private $_template; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * holds the incoming data object |
|
| 27 | - * |
|
| 28 | - * @access private |
|
| 29 | - * @var object |
|
| 30 | - */ |
|
| 31 | - private $_data; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * will hold an array of EE_Shortcodes library objects. |
|
| 36 | - * |
|
| 37 | - * @access private |
|
| 38 | - * @var EE_Shortcodes[] |
|
| 39 | - */ |
|
| 40 | - private $_shortcode_objs = array(); |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - public function __construct() |
|
| 44 | - { |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This kicks off the parsing of shortcodes in message templates |
|
| 50 | - * |
|
| 51 | - * @param string $template This is the incoming string to be parsed |
|
| 52 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
| 53 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
| 54 | - * @param EE_message_type $message_type The message type that called the parser |
|
| 55 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
| 56 | - * @param EE_Message $message |
|
| 57 | - * @return string The parsed template string |
|
| 58 | - */ |
|
| 59 | - public function parse_message_template( |
|
| 60 | - $template, |
|
| 61 | - EE_Messages_Addressee $data, |
|
| 62 | - $valid_shortcodes, |
|
| 63 | - EE_message_type $message_type, |
|
| 64 | - EE_messenger $messenger, |
|
| 65 | - EE_Message $message |
|
| 66 | - ) { |
|
| 67 | - $extra_data = array( |
|
| 68 | - 'messenger' => $messenger, |
|
| 69 | - 'message_type' => $message_type, |
|
| 70 | - 'message' => $message, |
|
| 71 | - ); |
|
| 72 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
| 73 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
| 74 | - return $this->_parse_message_template(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - public function parse_attendee_list_template( |
|
| 79 | - $template, |
|
| 80 | - EE_Registration $registration, |
|
| 81 | - $valid_shortcodes, |
|
| 82 | - $extra_data = array() |
|
| 83 | - ) { |
|
| 84 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
| 85 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
| 86 | - return $this->_parse_message_template(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
| 90 | - { |
|
| 91 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
| 92 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
| 93 | - return $this->_parse_message_template(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
| 98 | - { |
|
| 99 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
| 100 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
| 101 | - return $this->_parse_message_template(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - public function parse_line_item_list_template( |
|
| 106 | - $template, |
|
| 107 | - EE_Line_Item $line_item, |
|
| 108 | - $valid_shortcodes, |
|
| 109 | - $extra_data = array() |
|
| 110 | - ) { |
|
| 111 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
| 112 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
| 113 | - return $this->_parse_message_template(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - public function parse_payment_list_template( |
|
| 118 | - $template, |
|
| 119 | - EE_Payment $payment_item, |
|
| 120 | - $valid_shortcodes, |
|
| 121 | - $extra_data = array() |
|
| 122 | - ) { |
|
| 123 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
| 124 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
| 125 | - return $this->_parse_message_template(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - public function parse_datetime_list_template( |
|
| 130 | - $template, |
|
| 131 | - EE_Datetime $datetime, |
|
| 132 | - $valid_shortcodes, |
|
| 133 | - $extra_data = array() |
|
| 134 | - ) { |
|
| 135 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
| 136 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
| 137 | - return $this->_parse_message_template(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
| 142 | - { |
|
| 143 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
| 144 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
| 145 | - return $this->_parse_message_template(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
| 150 | - { |
|
| 151 | - $this->_reset_props(); |
|
| 152 | - $this->_data['template'] = $template; |
|
| 153 | - $this->_data['data'] = $data; |
|
| 154 | - $this->_data['extra_data'] = $extra_data; |
|
| 155 | - $this->_set_shortcodes($valid_shortcodes); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - private function _reset_props() |
|
| 160 | - { |
|
| 161 | - $this->_template = $this->_data = null; |
|
| 162 | - $this->_shortcode_objs = array(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * takes the given template and parses it with the $_shortcodes property |
|
| 168 | - * |
|
| 169 | - * @access private |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - private function _parse_message_template( $parsed = '' ) |
|
| 173 | - { |
|
| 174 | - $parsed = $parsed === '' ? $this->_template : $parsed; |
|
| 175 | - // now let's get a list of shortcodes that are found in the given template |
|
| 176 | - preg_match_all('/(?|(\[+[^\[\]]+\])|(\[.*\]))/', $parsed, $matches); |
|
| 177 | - $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
| 178 | - |
|
| 179 | - $matched_code = array(); |
|
| 180 | - $sc_values = array(); |
|
| 181 | - |
|
| 182 | - $list_type_shortcodes = array( |
|
| 183 | - '[ATTENDEE_LIST]', |
|
| 184 | - '[EVENT_LIST]', |
|
| 185 | - '[TICKET_LIST]', |
|
| 186 | - '[DATETIME_LIST]', |
|
| 187 | - '[QUESTION_LIST]', |
|
| 188 | - '[RECIPIENT_QUESTION_LIST]', |
|
| 189 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
| 190 | - '[RECIPIENT_TICKET_LIST]', |
|
| 191 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
| 192 | - '[RECIPIENT_DATETIME_LIST]', |
|
| 193 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
| 194 | - '[TICKET_LINE_ITEM_LIST]', |
|
| 195 | - '[TAX_LINE_ITEM_LIST]', |
|
| 196 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
| 197 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
| 198 | - '[PAYMENT_LIST_*]', |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - $list_type_shortcodes = apply_filters( |
|
| 202 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
| 203 | - $list_type_shortcodes |
|
| 204 | - ); |
|
| 205 | - |
|
| 206 | - $shortcodes_not_for_this_parser = []; |
|
| 207 | - |
|
| 208 | - // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
| 209 | - foreach ($shortcodes as $shortcode) { |
|
| 210 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
| 211 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
| 212 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
| 213 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
| 214 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
| 215 | - |
|
| 216 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
| 217 | - $shortcodes_not_for_this_parser[] = $sc_to_verify; |
|
| 218 | - continue; // the given shortcode isn't in this object |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
| 222 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
| 223 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
| 224 | - } else { |
|
| 225 | - $data_send = $this->_data; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
| 229 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
| 230 | - // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
| 231 | - // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
| 232 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
| 233 | - if ($parsed) { |
|
| 234 | - $this->_template = $parsed; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
| 239 | - |
|
| 240 | - $matched_code[] = $shortcode; |
|
| 241 | - $sc_values[] = $parsed; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
| 247 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
| 248 | - |
|
| 249 | - // are there any shortcodes left in the parsed content (might be nested) |
|
| 250 | - preg_match_all('/(?|(\[+[^\[\]]+\])|(\[.*\]))/', $parsed, $after_parsed); |
|
| 251 | - |
|
| 252 | - echo '<br>-------------<br>'; |
|
| 253 | - var_dump(count($after_parsed[0])); |
|
| 254 | - echo '<br>-------------<br>'; |
|
| 255 | - var_dump(count($shortcodes_not_for_this_parser)); |
|
| 256 | - |
|
| 257 | - if ( count($after_parsed[0]) > 0) { |
|
| 258 | - var_dump($after_parsed[0]); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (count($after_parsed[0]) === 1) { |
|
| 262 | - $parsed = $this->_parse_message_template( $parsed ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - return $parsed; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
| 272 | - * |
|
| 273 | - * Does it match this format: `[IF_` |
|
| 274 | - * |
|
| 275 | - * @param $shortcode |
|
| 276 | - */ |
|
| 277 | - protected function _is_conditional_shortcode($shortcode) |
|
| 278 | - { |
|
| 279 | - return strpos($shortcode, '[IF_') === 0; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
| 285 | - * various EE_Shortcode library objects |
|
| 286 | - * |
|
| 287 | - * @access private |
|
| 288 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
| 289 | - * @return void |
|
| 290 | - */ |
|
| 291 | - private function _set_shortcodes($valid_shortcodes) |
|
| 292 | - { |
|
| 293 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
| 294 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
| 295 | - $ref = str_replace(' ', '_', $ref); |
|
| 296 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 297 | - if (class_exists($classname)) { |
|
| 298 | - $this->_shortcode_objs[] = new $classname; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 16 | + /** |
|
| 17 | + * holds the template |
|
| 18 | + * |
|
| 19 | + * @access private |
|
| 20 | + * @var mixed (string|array) |
|
| 21 | + */ |
|
| 22 | + private $_template; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * holds the incoming data object |
|
| 27 | + * |
|
| 28 | + * @access private |
|
| 29 | + * @var object |
|
| 30 | + */ |
|
| 31 | + private $_data; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * will hold an array of EE_Shortcodes library objects. |
|
| 36 | + * |
|
| 37 | + * @access private |
|
| 38 | + * @var EE_Shortcodes[] |
|
| 39 | + */ |
|
| 40 | + private $_shortcode_objs = array(); |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + public function __construct() |
|
| 44 | + { |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This kicks off the parsing of shortcodes in message templates |
|
| 50 | + * |
|
| 51 | + * @param string $template This is the incoming string to be parsed |
|
| 52 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
| 53 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
| 54 | + * @param EE_message_type $message_type The message type that called the parser |
|
| 55 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
| 56 | + * @param EE_Message $message |
|
| 57 | + * @return string The parsed template string |
|
| 58 | + */ |
|
| 59 | + public function parse_message_template( |
|
| 60 | + $template, |
|
| 61 | + EE_Messages_Addressee $data, |
|
| 62 | + $valid_shortcodes, |
|
| 63 | + EE_message_type $message_type, |
|
| 64 | + EE_messenger $messenger, |
|
| 65 | + EE_Message $message |
|
| 66 | + ) { |
|
| 67 | + $extra_data = array( |
|
| 68 | + 'messenger' => $messenger, |
|
| 69 | + 'message_type' => $message_type, |
|
| 70 | + 'message' => $message, |
|
| 71 | + ); |
|
| 72 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
| 73 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
| 74 | + return $this->_parse_message_template(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + public function parse_attendee_list_template( |
|
| 79 | + $template, |
|
| 80 | + EE_Registration $registration, |
|
| 81 | + $valid_shortcodes, |
|
| 82 | + $extra_data = array() |
|
| 83 | + ) { |
|
| 84 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
| 85 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
| 86 | + return $this->_parse_message_template(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
| 90 | + { |
|
| 91 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
| 92 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
| 93 | + return $this->_parse_message_template(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
| 98 | + { |
|
| 99 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
| 100 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
| 101 | + return $this->_parse_message_template(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + public function parse_line_item_list_template( |
|
| 106 | + $template, |
|
| 107 | + EE_Line_Item $line_item, |
|
| 108 | + $valid_shortcodes, |
|
| 109 | + $extra_data = array() |
|
| 110 | + ) { |
|
| 111 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
| 112 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
| 113 | + return $this->_parse_message_template(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + public function parse_payment_list_template( |
|
| 118 | + $template, |
|
| 119 | + EE_Payment $payment_item, |
|
| 120 | + $valid_shortcodes, |
|
| 121 | + $extra_data = array() |
|
| 122 | + ) { |
|
| 123 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
| 124 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
| 125 | + return $this->_parse_message_template(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + public function parse_datetime_list_template( |
|
| 130 | + $template, |
|
| 131 | + EE_Datetime $datetime, |
|
| 132 | + $valid_shortcodes, |
|
| 133 | + $extra_data = array() |
|
| 134 | + ) { |
|
| 135 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
| 136 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
| 137 | + return $this->_parse_message_template(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
| 142 | + { |
|
| 143 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
| 144 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
| 145 | + return $this->_parse_message_template(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
| 150 | + { |
|
| 151 | + $this->_reset_props(); |
|
| 152 | + $this->_data['template'] = $template; |
|
| 153 | + $this->_data['data'] = $data; |
|
| 154 | + $this->_data['extra_data'] = $extra_data; |
|
| 155 | + $this->_set_shortcodes($valid_shortcodes); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + private function _reset_props() |
|
| 160 | + { |
|
| 161 | + $this->_template = $this->_data = null; |
|
| 162 | + $this->_shortcode_objs = array(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * takes the given template and parses it with the $_shortcodes property |
|
| 168 | + * |
|
| 169 | + * @access private |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + private function _parse_message_template( $parsed = '' ) |
|
| 173 | + { |
|
| 174 | + $parsed = $parsed === '' ? $this->_template : $parsed; |
|
| 175 | + // now let's get a list of shortcodes that are found in the given template |
|
| 176 | + preg_match_all('/(?|(\[+[^\[\]]+\])|(\[.*\]))/', $parsed, $matches); |
|
| 177 | + $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
| 178 | + |
|
| 179 | + $matched_code = array(); |
|
| 180 | + $sc_values = array(); |
|
| 181 | + |
|
| 182 | + $list_type_shortcodes = array( |
|
| 183 | + '[ATTENDEE_LIST]', |
|
| 184 | + '[EVENT_LIST]', |
|
| 185 | + '[TICKET_LIST]', |
|
| 186 | + '[DATETIME_LIST]', |
|
| 187 | + '[QUESTION_LIST]', |
|
| 188 | + '[RECIPIENT_QUESTION_LIST]', |
|
| 189 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
| 190 | + '[RECIPIENT_TICKET_LIST]', |
|
| 191 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
| 192 | + '[RECIPIENT_DATETIME_LIST]', |
|
| 193 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
| 194 | + '[TICKET_LINE_ITEM_LIST]', |
|
| 195 | + '[TAX_LINE_ITEM_LIST]', |
|
| 196 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
| 197 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
| 198 | + '[PAYMENT_LIST_*]', |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + $list_type_shortcodes = apply_filters( |
|
| 202 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
| 203 | + $list_type_shortcodes |
|
| 204 | + ); |
|
| 205 | + |
|
| 206 | + $shortcodes_not_for_this_parser = []; |
|
| 207 | + |
|
| 208 | + // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
| 209 | + foreach ($shortcodes as $shortcode) { |
|
| 210 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
| 211 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
| 212 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
| 213 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
| 214 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
| 215 | + |
|
| 216 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
| 217 | + $shortcodes_not_for_this_parser[] = $sc_to_verify; |
|
| 218 | + continue; // the given shortcode isn't in this object |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
| 222 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
| 223 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
| 224 | + } else { |
|
| 225 | + $data_send = $this->_data; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
| 229 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
| 230 | + // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
| 231 | + // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
| 232 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
| 233 | + if ($parsed) { |
|
| 234 | + $this->_template = $parsed; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
| 239 | + |
|
| 240 | + $matched_code[] = $shortcode; |
|
| 241 | + $sc_values[] = $parsed; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
| 247 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
| 248 | + |
|
| 249 | + // are there any shortcodes left in the parsed content (might be nested) |
|
| 250 | + preg_match_all('/(?|(\[+[^\[\]]+\])|(\[.*\]))/', $parsed, $after_parsed); |
|
| 251 | + |
|
| 252 | + echo '<br>-------------<br>'; |
|
| 253 | + var_dump(count($after_parsed[0])); |
|
| 254 | + echo '<br>-------------<br>'; |
|
| 255 | + var_dump(count($shortcodes_not_for_this_parser)); |
|
| 256 | + |
|
| 257 | + if ( count($after_parsed[0]) > 0) { |
|
| 258 | + var_dump($after_parsed[0]); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (count($after_parsed[0]) === 1) { |
|
| 262 | + $parsed = $this->_parse_message_template( $parsed ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + return $parsed; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
| 272 | + * |
|
| 273 | + * Does it match this format: `[IF_` |
|
| 274 | + * |
|
| 275 | + * @param $shortcode |
|
| 276 | + */ |
|
| 277 | + protected function _is_conditional_shortcode($shortcode) |
|
| 278 | + { |
|
| 279 | + return strpos($shortcode, '[IF_') === 0; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
| 285 | + * various EE_Shortcode library objects |
|
| 286 | + * |
|
| 287 | + * @access private |
|
| 288 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
| 289 | + * @return void |
|
| 290 | + */ |
|
| 291 | + private function _set_shortcodes($valid_shortcodes) |
|
| 292 | + { |
|
| 293 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
| 294 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
| 295 | + $ref = str_replace(' ', '_', $ref); |
|
| 296 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 297 | + if (class_exists($classname)) { |
|
| 298 | + $this->_shortcode_objs[] = new $classname; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @access private |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - private function _parse_message_template( $parsed = '' ) |
|
| 172 | + private function _parse_message_template($parsed = '') |
|
| 173 | 173 | { |
| 174 | 174 | $parsed = $parsed === '' ? $this->_template : $parsed; |
| 175 | 175 | // now let's get a list of shortcodes that are found in the given template |
@@ -211,15 +211,15 @@ discard block |
||
| 211 | 211 | if ($sc_obj instanceof EE_Shortcodes) { |
| 212 | 212 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
| 213 | 213 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
| 214 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
| 214 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
| 215 | 215 | |
| 216 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
| 216 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
| 217 | 217 | $shortcodes_not_for_this_parser[] = $sc_to_verify; |
| 218 | 218 | continue; // the given shortcode isn't in this object |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
| 222 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
| 222 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
| 223 | 223 | $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
| 224 | 224 | } else { |
| 225 | 225 | $data_send = $this->_data; |
@@ -254,12 +254,12 @@ discard block |
||
| 254 | 254 | echo '<br>-------------<br>'; |
| 255 | 255 | var_dump(count($shortcodes_not_for_this_parser)); |
| 256 | 256 | |
| 257 | - if ( count($after_parsed[0]) > 0) { |
|
| 257 | + if (count($after_parsed[0]) > 0) { |
|
| 258 | 258 | var_dump($after_parsed[0]); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | if (count($after_parsed[0]) === 1) { |
| 262 | - $parsed = $this->_parse_message_template( $parsed ); |
|
| 262 | + $parsed = $this->_parse_message_template($parsed); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | foreach ($valid_shortcodes as $shortcode_ref) { |
| 294 | 294 | $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
| 295 | 295 | $ref = str_replace(' ', '_', $ref); |
| 296 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 296 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
| 297 | 297 | if (class_exists($classname)) { |
| 298 | 298 | $this->_shortcode_objs[] = new $classname; |
| 299 | 299 | } |