@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
| 149 | 149 | the_content(); |
| 150 | 150 | } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
| 151 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 151 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 152 | 152 | // AND an excerpt actually exists |
| 153 | 153 | the_excerpt(); |
| 154 | 154 | } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
| 155 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 155 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 156 | 156 | // but NO excerpt actually exists, so we need to create one |
| 157 | 157 | if ( ! empty( $num_words )) { |
| 158 | 158 | if ( empty( $more )) { |
@@ -161,32 +161,32 @@ discard block |
||
| 161 | 161 | $more .= ' class="more-link"'; |
| 162 | 162 | $more .= \EED_Events_Archive::link_target(); |
| 163 | 163 | $more .= '>' . $more_link_text . '</a>'; |
| 164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 164 | + $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 165 | 165 | } |
| 166 | 166 | $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
| 167 | 167 | |
| 168 | 168 | $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
| 169 | - } else { |
|
| 170 | - $content = get_the_content(); |
|
| 169 | + } else { |
|
| 170 | + $content = get_the_content(); |
|
| 171 | 171 | } |
| 172 | 172 | global $allowedtags; |
| 173 | 173 | // make sure links are allowed |
| 174 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
| 175 | - ? $allowedtags['a'] |
|
| 176 | - : array(); |
|
| 177 | - // as well as target attribute |
|
| 178 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 179 | - ? $allowedtags['a']['target'] |
|
| 180 | - : false; |
|
| 181 | - // but get previous value so we can reset it |
|
| 182 | - $prev_value = $allowedtags['a']['target']; |
|
| 183 | - $allowedtags['a']['target'] = true; |
|
| 174 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
| 175 | + ? $allowedtags['a'] |
|
| 176 | + : array(); |
|
| 177 | + // as well as target attribute |
|
| 178 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 179 | + ? $allowedtags['a']['target'] |
|
| 180 | + : false; |
|
| 181 | + // but get previous value so we can reset it |
|
| 182 | + $prev_value = $allowedtags['a']['target']; |
|
| 183 | + $allowedtags['a']['target'] = true; |
|
| 184 | 184 | $content = wp_kses( $content, $allowedtags ); |
| 185 | 185 | $content = strip_shortcodes( $content ); |
| 186 | 186 | echo apply_filters( 'the_content', $content ); |
| 187 | 187 | $allowedtags['a']['target'] = $prev_value; |
| 188 | - } else { |
|
| 189 | - // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 188 | + } else { |
|
| 189 | + // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 190 | 190 | echo apply_filters( 'the_content', '' ); |
| 191 | 191 | } |
| 192 | 192 | return ob_get_clean(); |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | $url = get_term_link( $term, 'espresso_venue_categories' ); |
| 235 | 235 | if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
| 236 | 236 | $category_links[] = '<a href="' . esc_url( $url ) |
| 237 | - . '" rel="tag"' |
|
| 238 | - . \EED_Events_Archive::link_target() |
|
| 239 | - .'>' |
|
| 240 | - . $term->name |
|
| 241 | - . '</a>'; |
|
| 237 | + . '" rel="tag"' |
|
| 238 | + . \EED_Events_Archive::link_target() |
|
| 239 | + .'>' |
|
| 240 | + . $term->name |
|
| 241 | + . '</a>'; |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -40,27 +40,27 @@ discard block |
||
| 40 | 40 | * @param int $EVT_ID |
| 41 | 41 | * @return object |
| 42 | 42 | */ |
| 43 | - public static function get_event( $EVT_ID = 0 ) { |
|
| 44 | - $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint( $EVT_ID ); |
|
| 43 | + public static function get_event($EVT_ID = 0) { |
|
| 44 | + $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint($EVT_ID); |
|
| 45 | 45 | // do we already have the Event you are looking for? |
| 46 | - if ( EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID ) { |
|
| 46 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
| 47 | 47 | return EEH_Event_View::$_event; |
| 48 | 48 | } |
| 49 | 49 | EEH_Event_View::$_event = NULL; |
| 50 | 50 | // international newspaper? |
| 51 | 51 | global $post; |
| 52 | 52 | // if this is being called from an EE_Event post, then we can just grab the attached EE_Event object |
| 53 | - if ( isset( $post->post_type ) && $post->post_type == 'espresso_events' || $EVT_ID ) { |
|
| 53 | + if (isset($post->post_type) && $post->post_type == 'espresso_events' || $EVT_ID) { |
|
| 54 | 54 | // d( $post ); |
| 55 | 55 | // grab the event we're looking for |
| 56 | - if ( isset( $post->EE_Event ) && ( $EVT_ID == 0 || ( $EVT_ID == $post->ID ))) { |
|
| 56 | + if (isset($post->EE_Event) && ($EVT_ID == 0 || ($EVT_ID == $post->ID))) { |
|
| 57 | 57 | EEH_Event_View::$_event = $post->EE_Event; |
| 58 | 58 | // d( EEH_Event_View::$_event ); |
| 59 | 59 | } |
| 60 | 60 | // now if we STILL do NOT have an EE_Event model object, BUT we have an Event ID... |
| 61 | - if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID ) { |
|
| 61 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
| 62 | 62 | // sigh... pull it from the db |
| 63 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
| 63 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 64 | 64 | // d( EEH_Event_View::$_event ); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @param int $EVT_ID |
| 77 | 77 | * @return boolean |
| 78 | 78 | */ |
| 79 | - public static function display_ticket_selector( $EVT_ID = 0 ) { |
|
| 80 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 79 | + public static function display_ticket_selector($EVT_ID = 0) { |
|
| 80 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 81 | 81 | return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | * @param int $EVT_ID |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public static function event_status( $EVT_ID = 0 ) { |
|
| 94 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 95 | - return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : ''; |
|
| 93 | + public static function event_status($EVT_ID = 0) { |
|
| 94 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 95 | + return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : ''; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @param int $EVT_ID |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public static function event_active_status( $EVT_ID = 0 ) { |
|
| 108 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 107 | + public static function event_active_status($EVT_ID = 0) { |
|
| 108 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 109 | 109 | return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive'; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | * @param int $EVT_ID |
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | - public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
|
| 122 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 121 | + public static function event_has_content_or_excerpt($EVT_ID = 0) { |
|
| 122 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 123 | 123 | $has_content_or_excerpt = FALSE; |
| 124 | - if ( $event instanceof EE_Event ) { |
|
| 125 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE; |
|
| 124 | + if ($event instanceof EE_Event) { |
|
| 125 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE; |
|
| 126 | 126 | } |
| 127 | - if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
| 127 | + if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) { |
|
| 128 | 128 | $has_content_or_excerpt = FALSE; |
| 129 | 129 | } |
| 130 | 130 | return $has_content_or_excerpt; |
@@ -140,34 +140,34 @@ discard block |
||
| 140 | 140 | * @param null $more |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
|
| 143 | + public static function event_content_or_excerpt($num_words = NULL, $more = NULL) { |
|
| 144 | 144 | global $post; |
| 145 | 145 | |
| 146 | 146 | ob_start(); |
| 147 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
| 147 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
| 148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
| 149 | 149 | the_content(); |
| 150 | - } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
|
| 150 | + } else if ((is_archive() && has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
| 151 | 151 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
| 152 | 152 | // AND an excerpt actually exists |
| 153 | 153 | the_excerpt(); |
| 154 | - } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
|
| 154 | + } else if ((is_archive() && ! has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
| 155 | 155 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
| 156 | 156 | // but NO excerpt actually exists, so we need to create one |
| 157 | - if ( ! empty( $num_words )) { |
|
| 158 | - if ( empty( $more )) { |
|
| 159 | - $more_link_text = __( '(more…)' ); |
|
| 160 | - $more = ' <a href="' . get_permalink() . '"'; |
|
| 157 | + if ( ! empty($num_words)) { |
|
| 158 | + if (empty($more)) { |
|
| 159 | + $more_link_text = __('(more…)'); |
|
| 160 | + $more = ' <a href="'.get_permalink().'"'; |
|
| 161 | 161 | $more .= ' class="more-link"'; |
| 162 | 162 | $more .= \EED_Events_Archive::link_target(); |
| 163 | - $more .= '>' . $more_link_text . '</a>'; |
|
| 164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 163 | + $more .= '>'.$more_link_text.'</a>'; |
|
| 164 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
| 165 | 165 | } |
| 166 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
| 166 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
| 167 | 167 | |
| 168 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
| 168 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
| 169 | 169 | } else { |
| 170 | - $content = get_the_content(); |
|
| 170 | + $content = get_the_content(); |
|
| 171 | 171 | } |
| 172 | 172 | global $allowedtags; |
| 173 | 173 | // make sure links are allowed |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | // but get previous value so we can reset it |
| 182 | 182 | $prev_value = $allowedtags['a']['target']; |
| 183 | 183 | $allowedtags['a']['target'] = true; |
| 184 | - $content = wp_kses( $content, $allowedtags ); |
|
| 185 | - $content = strip_shortcodes( $content ); |
|
| 186 | - echo apply_filters( 'the_content', $content ); |
|
| 184 | + $content = wp_kses($content, $allowedtags); |
|
| 185 | + $content = strip_shortcodes($content); |
|
| 186 | + echo apply_filters('the_content', $content); |
|
| 187 | 187 | $allowedtags['a']['target'] = $prev_value; |
| 188 | 188 | } else { |
| 189 | 189 | // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
| 190 | - echo apply_filters( 'the_content', '' ); |
|
| 190 | + echo apply_filters('the_content', ''); |
|
| 191 | 191 | } |
| 192 | 192 | return ob_get_clean(); |
| 193 | 193 | } |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | * @param int $EVT_ID |
| 202 | 202 | * @return EE_Ticket[] |
| 203 | 203 | */ |
| 204 | - public static function event_tickets_available( $EVT_ID = 0 ) { |
|
| 205 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 204 | + public static function event_tickets_available($EVT_ID = 0) { |
|
| 205 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 206 | 206 | $tickets_available_for_purchase = array(); |
| 207 | - if( $event instanceof EE_Event ) { |
|
| 208 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE ); |
|
| 209 | - foreach( $datetimes as $datetime ) { |
|
| 210 | - $tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() ); |
|
| 207 | + if ($event instanceof EE_Event) { |
|
| 208 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE); |
|
| 209 | + foreach ($datetimes as $datetime) { |
|
| 210 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | return $tickets_available_for_purchase; |
@@ -223,17 +223,17 @@ discard block |
||
| 223 | 223 | * @param bool $hide_uncategorized |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) { |
|
| 226 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) { |
|
| 227 | 227 | $category_links = array(); |
| 228 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 229 | - if ( $event instanceof EE_Event ) { |
|
| 230 | - $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' ); |
|
| 231 | - if ( $event_categories ) { |
|
| 228 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 229 | + if ($event instanceof EE_Event) { |
|
| 230 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
| 231 | + if ($event_categories) { |
|
| 232 | 232 | // loop thru terms and create links |
| 233 | - foreach ( $event_categories as $term ) { |
|
| 234 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
| 235 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
| 236 | - $category_links[] = '<a href="' . esc_url( $url ) |
|
| 233 | + foreach ($event_categories as $term) { |
|
| 234 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 235 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
| 236 | + $category_links[] = '<a href="'.esc_url($url) |
|
| 237 | 237 | . '" rel="tag"' |
| 238 | 238 | . \EED_Events_Archive::link_target() |
| 239 | 239 | .'>' |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | - return implode( ', ', $category_links ); |
|
| 246 | + return implode(', ', $category_links); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | * @param int $EVT_ID |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | - public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 261 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 262 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 263 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
| 260 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 261 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 262 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 263 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -274,10 +274,10 @@ discard block |
||
| 274 | 274 | * @param int $EVT_ID |
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | - public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 278 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
| 279 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 280 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
| 277 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 278 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 279 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 280 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | |
@@ -291,10 +291,10 @@ discard block |
||
| 291 | 291 | * @param int $EVT_ID |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 295 | - $datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID ); |
|
| 296 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 297 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
| 294 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 295 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
| 296 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 297 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -308,10 +308,10 @@ discard block |
||
| 308 | 308 | * @param int $EVT_ID |
| 309 | 309 | * @return string |
| 310 | 310 | */ |
| 311 | - public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 312 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
| 313 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 314 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
| 311 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 312 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 313 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 314 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * @param int $EVT_ID |
| 324 | 324 | * @return string |
| 325 | 325 | */ |
| 326 | - public static function event_date_as_calendar_page( $EVT_ID = 0 ) { |
|
| 327 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 328 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 326 | + public static function event_date_as_calendar_page($EVT_ID = 0) { |
|
| 327 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 328 | + if ($datetime instanceof EE_Datetime) { |
|
| 329 | 329 | ?> |
| 330 | 330 | <div class="event-date-calendar-page-dv"> |
| 331 | - <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div> |
|
| 332 | - <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div> |
|
| 331 | + <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div> |
|
| 332 | + <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div> |
|
| 333 | 333 | </div> |
| 334 | 334 | <?php |
| 335 | 335 | } |
@@ -344,17 +344,17 @@ discard block |
||
| 344 | 344 | * @param int $EVT_ID |
| 345 | 345 | * @return string |
| 346 | 346 | */ |
| 347 | - public static function get_primary_date_obj( $EVT_ID = 0 ) { |
|
| 348 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 349 | - if ( $event instanceof EE_Event ) { |
|
| 347 | + public static function get_primary_date_obj($EVT_ID = 0) { |
|
| 348 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 349 | + if ($event instanceof EE_Event) { |
|
| 350 | 350 | $datetimes = $event->get_many_related( |
| 351 | 351 | 'Datetime', |
| 352 | 352 | array( |
| 353 | 353 | 'limit' => 1, |
| 354 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
| 354 | + 'order_by' => array('DTT_order' => 'ASC') |
|
| 355 | 355 | ) |
| 356 | 356 | ); |
| 357 | - return reset( $datetimes ); |
|
| 357 | + return reset($datetimes); |
|
| 358 | 358 | } else { |
| 359 | 359 | return FALSE; |
| 360 | 360 | } |
@@ -369,17 +369,17 @@ discard block |
||
| 369 | 369 | * @param int $EVT_ID |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - public static function get_last_date_obj( $EVT_ID = 0 ) { |
|
| 373 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 374 | - if ( $event instanceof EE_Event ) { |
|
| 372 | + public static function get_last_date_obj($EVT_ID = 0) { |
|
| 373 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 374 | + if ($event instanceof EE_Event) { |
|
| 375 | 375 | $datetimes = $event->get_many_related( |
| 376 | 376 | 'Datetime', |
| 377 | 377 | array( |
| 378 | 378 | 'limit' => 1, |
| 379 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
| 379 | + 'order_by' => array('DTT_order' => 'DESC') |
|
| 380 | 380 | ) |
| 381 | 381 | ); |
| 382 | - return end( $datetimes ); |
|
| 382 | + return end($datetimes); |
|
| 383 | 383 | } else { |
| 384 | 384 | return FALSE; |
| 385 | 385 | } |
@@ -394,17 +394,17 @@ discard block |
||
| 394 | 394 | * @param int $EVT_ID |
| 395 | 395 | * @return string |
| 396 | 396 | */ |
| 397 | - public static function get_earliest_date_obj( $EVT_ID = 0 ) { |
|
| 398 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 399 | - if ( $event instanceof EE_Event ) { |
|
| 397 | + public static function get_earliest_date_obj($EVT_ID = 0) { |
|
| 398 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 399 | + if ($event instanceof EE_Event) { |
|
| 400 | 400 | $datetimes = $event->get_many_related( |
| 401 | 401 | 'Datetime', |
| 402 | 402 | array( |
| 403 | 403 | 'limit' => 1, |
| 404 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
| 404 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
| 405 | 405 | ) |
| 406 | 406 | ); |
| 407 | - return reset( $datetimes ); |
|
| 407 | + return reset($datetimes); |
|
| 408 | 408 | } else { |
| 409 | 409 | return FALSE; |
| 410 | 410 | } |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @param int $EVT_ID |
| 420 | 420 | * @return string |
| 421 | 421 | */ |
| 422 | - public static function get_latest_date_obj( $EVT_ID = 0 ) { |
|
| 423 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 424 | - if ( $event instanceof EE_Event ) { |
|
| 422 | + public static function get_latest_date_obj($EVT_ID = 0) { |
|
| 423 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 424 | + if ($event instanceof EE_Event) { |
|
| 425 | 425 | $datetimes = $event->get_many_related( |
| 426 | 426 | 'Datetime', |
| 427 | 427 | array( |
| 428 | 428 | 'limit' => 1, |
| 429 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
| 429 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
| 430 | 430 | ) |
| 431 | 431 | ); |
| 432 | - return end( $datetimes ); |
|
| 432 | + return end($datetimes); |
|
| 433 | 433 | } else { |
| 434 | 434 | return FALSE; |
| 435 | 435 | } |
@@ -447,17 +447,17 @@ discard block |
||
| 447 | 447 | * @param null $limit |
| 448 | 448 | * @return EE_Datetime[] |
| 449 | 449 | */ |
| 450 | - public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) { |
|
| 451 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 452 | - if($include_expired === null){ |
|
| 453 | - if($event instanceof EE_Event && $event->is_expired()){ |
|
| 450 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) { |
|
| 451 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 452 | + if ($include_expired === null) { |
|
| 453 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
| 454 | 454 | $include_expired = true; |
| 455 | - }else{ |
|
| 455 | + } else { |
|
| 456 | 456 | $include_expired = false; |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( $event instanceof EE_Event ) { |
|
| 460 | + if ($event instanceof EE_Event) { |
|
| 461 | 461 | return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
| 462 | 462 | } else { |
| 463 | 463 | return array(); |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | * @param int $EVT_ID |
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | - public static function event_link_url( $EVT_ID = 0 ) { |
|
| 477 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 478 | - if ( $event instanceof EE_Event ) { |
|
| 479 | - $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() ); |
|
| 480 | - return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url; |
|
| 476 | + public static function event_link_url($EVT_ID = 0) { |
|
| 477 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 478 | + if ($event instanceof EE_Event) { |
|
| 479 | + $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
| 480 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url; |
|
| 481 | 481 | } |
| 482 | 482 | return NULL; |
| 483 | 483 | } |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | * @param int $EVT_ID |
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | - public static function event_phone( $EVT_ID = 0 ) { |
|
| 495 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 496 | - if ( $event instanceof EE_Event ) { |
|
| 497 | - return EEH_Schema::telephone( $event->phone() ); |
|
| 494 | + public static function event_phone($EVT_ID = 0) { |
|
| 495 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 496 | + if ($event instanceof EE_Event) { |
|
| 497 | + return EEH_Schema::telephone($event->phone()); |
|
| 498 | 498 | } |
| 499 | 499 | return NULL; |
| 500 | 500 | } |
@@ -511,26 +511,26 @@ discard block |
||
| 511 | 511 | * @param string $after |
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | - public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) { |
|
| 515 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 516 | - if ( $event instanceof EE_Event ) { |
|
| 514 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') { |
|
| 515 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 516 | + if ($event instanceof EE_Event) { |
|
| 517 | 517 | // can the user edit this post ? |
| 518 | - if ( current_user_can( 'edit_post', $event->ID() )) { |
|
| 518 | + if (current_user_can('edit_post', $event->ID())) { |
|
| 519 | 519 | // set link text |
| 520 | - $link_text = ! empty( $link ) ? $link : __('edit this event'); |
|
| 520 | + $link_text = ! empty($link) ? $link : __('edit this event'); |
|
| 521 | 521 | // generate nonce |
| 522 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
| 522 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 523 | 523 | // generate url to event editor for this event |
| 524 | - $url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() ); |
|
| 524 | + $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url()); |
|
| 525 | 525 | // get edit CPT text |
| 526 | - $post_type_obj = get_post_type_object( 'espresso_events' ); |
|
| 526 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
| 527 | 527 | // build final link html |
| 528 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
| 529 | - $link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"'; |
|
| 528 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
| 529 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
| 530 | 530 | $link .= \EED_Events_Archive::link_target(); |
| 531 | - $link .='>' . $link_text . '</a>'; |
|
| 531 | + $link .= '>'.$link_text.'</a>'; |
|
| 532 | 532 | // put it all together |
| 533 | - return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after; |
|
| 533 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | return ''; |
@@ -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 | * Event Espresso |
@@ -16,35 +16,35 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | if ( ! function_exists('espresso_get_template_part')) { |
| 19 | - /** |
|
| 20 | - * espresso_get_template_part |
|
| 21 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 22 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 23 | - * |
|
| 24 | - * @param string $slug The slug name for the generic template. |
|
| 25 | - * @param string $name The name of the specialised template. |
|
| 26 | - * @return string the html output for the formatted money value |
|
| 27 | - */ |
|
| 28 | - function espresso_get_template_part($slug = null, $name = null) |
|
| 29 | - { |
|
| 30 | - EEH_Template::get_template_part($slug, $name); |
|
| 31 | - } |
|
| 19 | + /** |
|
| 20 | + * espresso_get_template_part |
|
| 21 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 22 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 23 | + * |
|
| 24 | + * @param string $slug The slug name for the generic template. |
|
| 25 | + * @param string $name The name of the specialised template. |
|
| 26 | + * @return string the html output for the formatted money value |
|
| 27 | + */ |
|
| 28 | + function espresso_get_template_part($slug = null, $name = null) |
|
| 29 | + { |
|
| 30 | + EEH_Template::get_template_part($slug, $name); |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | if ( ! function_exists('espresso_get_object_css_class')) { |
| 36 | - /** |
|
| 37 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 38 | - * |
|
| 39 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 40 | - * @param string $prefix added to the beginning of the generated class |
|
| 41 | - * @param string $suffix added to the end of the generated class |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 45 | - { |
|
| 46 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 38 | + * |
|
| 39 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 40 | + * @param string $prefix added to the beginning of the generated class |
|
| 41 | + * @param string $suffix added to the end of the generated class |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 45 | + { |
|
| 46 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -59,648 +59,648 @@ discard block |
||
| 59 | 59 | class EEH_Template |
| 60 | 60 | { |
| 61 | 61 | |
| 62 | - private static $_espresso_themes = array(); |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 67 | - * |
|
| 68 | - * @return boolean |
|
| 69 | - */ |
|
| 70 | - public static function is_espresso_theme() |
|
| 71 | - { |
|
| 72 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 77 | - * load it's functions.php file ( if not already loaded ) |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function load_espresso_theme_functions() |
|
| 82 | - { |
|
| 83 | - if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
| 85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 93 | - * |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public static function get_espresso_themes() |
|
| 97 | - { |
|
| 98 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
| 99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 100 | - if (empty($espresso_themes)) { |
|
| 101 | - return array(); |
|
| 102 | - } |
|
| 103 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 104 | - unset($espresso_themes[$key]); |
|
| 105 | - } |
|
| 106 | - EEH_Template::$_espresso_themes = array(); |
|
| 107 | - foreach ($espresso_themes as $espresso_theme) { |
|
| 108 | - EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - return EEH_Template::$_espresso_themes; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * EEH_Template::get_template_part |
|
| 117 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 118 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 119 | - * filtering based off of the entire template part name |
|
| 120 | - * |
|
| 121 | - * @param string $slug The slug name for the generic template. |
|
| 122 | - * @param string $name The name of the specialised template. |
|
| 123 | - * @param array $template_args |
|
| 124 | - * @param bool $return_string |
|
| 125 | - * @return string the html output for the formatted money value |
|
| 126 | - */ |
|
| 127 | - public static function get_template_part( |
|
| 128 | - $slug = null, |
|
| 129 | - $name = null, |
|
| 130 | - $template_args = array(), |
|
| 131 | - $return_string = false |
|
| 132 | - ) { |
|
| 133 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 134 | - $templates = array(); |
|
| 135 | - $name = (string)$name; |
|
| 136 | - if ($name != '') { |
|
| 137 | - $templates[] = "{$slug}-{$name}.php"; |
|
| 138 | - } |
|
| 139 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 140 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 141 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * locate_template |
|
| 148 | - * locate a template file by looking in the following places, in the following order: |
|
| 149 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 150 | - * <assumed full absolute server path> |
|
| 151 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 152 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 153 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 154 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 155 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 156 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 157 | - * Example: |
|
| 158 | - * You are using the WordPress Twenty Sixteen theme, |
|
| 159 | - * and you want to customize the "some-event.template.php" template, |
|
| 160 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 161 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 162 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 163 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 164 | - * /relative/path/to/some-event.template.php |
|
| 165 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 166 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 167 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 168 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 169 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 170 | - * Had you passed an absolute path to your template that was in some other location, |
|
| 171 | - * ie: "/absolute/path/to/some-event.template.php" |
|
| 172 | - * then the search would have been : |
|
| 173 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 174 | - * /absolute/path/to/some-event.template.php |
|
| 175 | - * and stopped there upon finding it in the second location |
|
| 176 | - * |
|
| 177 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 178 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 179 | - * @param boolean $load whether to pass the located template path on to the |
|
| 180 | - * EEH_Template::display_template() method or simply return it |
|
| 181 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 182 | - * string |
|
| 183 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 184 | - * generate a custom template or not. Used in places where you don't actually |
|
| 185 | - * load the template, you just want to know if there's a custom version of it. |
|
| 186 | - * @return mixed |
|
| 187 | - */ |
|
| 188 | - public static function locate_template( |
|
| 189 | - $templates = array(), |
|
| 190 | - $template_args = array(), |
|
| 191 | - $load = true, |
|
| 192 | - $return_string = true, |
|
| 193 | - $check_if_custom = false |
|
| 194 | - ) { |
|
| 195 | - // first use WP locate_template to check for template in the current theme folder |
|
| 196 | - $template_path = locate_template($templates); |
|
| 197 | - |
|
| 198 | - if ($check_if_custom && ! empty($template_path)) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // not in the theme |
|
| 203 | - if (empty($template_path)) { |
|
| 204 | - // not even a template to look for ? |
|
| 205 | - if (empty($templates)) { |
|
| 206 | - // get post_type |
|
| 207 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
| 208 | - // get array of EE Custom Post Types |
|
| 209 | - $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
| 210 | - // build template name based on request |
|
| 211 | - if (isset($EE_CPTs[$post_type])) { |
|
| 212 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 213 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - // currently active EE template theme |
|
| 218 | - $current_theme = EE_Config::get_current_theme(); |
|
| 219 | - |
|
| 220 | - // array of paths to folders that may contain templates |
|
| 221 | - $template_folder_paths = array( |
|
| 222 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 224 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 225 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 226 | - ); |
|
| 227 | - |
|
| 228 | - //add core plugin folders for checking only if we're not $check_if_custom |
|
| 229 | - if ( ! $check_if_custom) { |
|
| 230 | - $core_paths = array( |
|
| 231 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 232 | - EE_PUBLIC . $current_theme, |
|
| 233 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 234 | - EE_TEMPLATES . $current_theme, |
|
| 235 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 236 | - EE_PLUGIN_DIR_PATH, |
|
| 237 | - ); |
|
| 238 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // now filter that array |
|
| 242 | - $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 243 | - $template_folder_paths); |
|
| 244 | - $templates = is_array($templates) ? $templates : array($templates); |
|
| 245 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
| 246 | - // array to hold all possible template paths |
|
| 247 | - $full_template_paths = array(); |
|
| 248 | - |
|
| 249 | - // loop through $templates |
|
| 250 | - foreach ($templates as $template) { |
|
| 251 | - // normalize directory separators |
|
| 252 | - $template = EEH_File::standardise_directory_separators($template); |
|
| 253 | - $file_name = basename($template); |
|
| 254 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 255 | - // while looping through all template folder paths |
|
| 256 | - foreach ($template_folder_paths as $template_folder_path) { |
|
| 257 | - // normalize directory separators |
|
| 258 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 259 | - // determine if any common base path exists between the two paths |
|
| 260 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
| 261 | - array($template_folder_path, $template_path_minus_file_name) |
|
| 262 | - ); |
|
| 263 | - if ($common_base_path !== '') { |
|
| 264 | - // both paths have a common base, so just tack the filename onto our search path |
|
| 265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 266 | - } else { |
|
| 267 | - // no common base path, so let's just concatenate |
|
| 268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 269 | - } |
|
| 270 | - // build up our template locations array by adding our resolved paths |
|
| 271 | - $full_template_paths[] = $resolved_path; |
|
| 272 | - } |
|
| 273 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 274 | - array_unshift($full_template_paths, $template); |
|
| 275 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
| 277 | - } |
|
| 278 | - // filter final array of full template paths |
|
| 279 | - $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 280 | - $full_template_paths, $file_name); |
|
| 281 | - // now loop through our final array of template location paths and check each location |
|
| 282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
| 283 | - if (is_readable($full_template_path)) { |
|
| 284 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
| 285 | - // hook that can be used to display the full template path that will be used |
|
| 286 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - // if we got it and you want to see it... |
|
| 292 | - if ($template_path && $load && ! $check_if_custom) { |
|
| 293 | - if ($return_string) { |
|
| 294 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
| 295 | - } else { |
|
| 296 | - EEH_Template::display_template($template_path, $template_args, false); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * _find_common_base_path |
|
| 305 | - * given two paths, this determines if there is a common base path between the two |
|
| 306 | - * |
|
| 307 | - * @param array $paths |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - protected static function _find_common_base_path($paths) |
|
| 311 | - { |
|
| 312 | - $last_offset = 0; |
|
| 313 | - $common_base_path = ''; |
|
| 314 | - while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
| 315 | - $dir_length = $index - $last_offset + 1; |
|
| 316 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 317 | - foreach ($paths as $path) { |
|
| 318 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 319 | - return $common_base_path; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - $common_base_path .= $directory; |
|
| 323 | - $last_offset = $index + 1; |
|
| 324 | - } |
|
| 325 | - return substr($common_base_path, 0, -1); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * load and display a template |
|
| 331 | - * |
|
| 332 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 333 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 334 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
| 335 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 336 | - * not found or is not readable |
|
| 337 | - * @return mixed string |
|
| 338 | - * @throws \DomainException |
|
| 339 | - */ |
|
| 62 | + private static $_espresso_themes = array(); |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 67 | + * |
|
| 68 | + * @return boolean |
|
| 69 | + */ |
|
| 70 | + public static function is_espresso_theme() |
|
| 71 | + { |
|
| 72 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 77 | + * load it's functions.php file ( if not already loaded ) |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function load_espresso_theme_functions() |
|
| 82 | + { |
|
| 83 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 84 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
| 85 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 93 | + * |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public static function get_espresso_themes() |
|
| 97 | + { |
|
| 98 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
| 99 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 100 | + if (empty($espresso_themes)) { |
|
| 101 | + return array(); |
|
| 102 | + } |
|
| 103 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 104 | + unset($espresso_themes[$key]); |
|
| 105 | + } |
|
| 106 | + EEH_Template::$_espresso_themes = array(); |
|
| 107 | + foreach ($espresso_themes as $espresso_theme) { |
|
| 108 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + return EEH_Template::$_espresso_themes; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * EEH_Template::get_template_part |
|
| 117 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 118 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 119 | + * filtering based off of the entire template part name |
|
| 120 | + * |
|
| 121 | + * @param string $slug The slug name for the generic template. |
|
| 122 | + * @param string $name The name of the specialised template. |
|
| 123 | + * @param array $template_args |
|
| 124 | + * @param bool $return_string |
|
| 125 | + * @return string the html output for the formatted money value |
|
| 126 | + */ |
|
| 127 | + public static function get_template_part( |
|
| 128 | + $slug = null, |
|
| 129 | + $name = null, |
|
| 130 | + $template_args = array(), |
|
| 131 | + $return_string = false |
|
| 132 | + ) { |
|
| 133 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 134 | + $templates = array(); |
|
| 135 | + $name = (string)$name; |
|
| 136 | + if ($name != '') { |
|
| 137 | + $templates[] = "{$slug}-{$name}.php"; |
|
| 138 | + } |
|
| 139 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 140 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 141 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * locate_template |
|
| 148 | + * locate a template file by looking in the following places, in the following order: |
|
| 149 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 150 | + * <assumed full absolute server path> |
|
| 151 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 152 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 153 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 154 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 155 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 156 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 157 | + * Example: |
|
| 158 | + * You are using the WordPress Twenty Sixteen theme, |
|
| 159 | + * and you want to customize the "some-event.template.php" template, |
|
| 160 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 161 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 162 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 163 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 164 | + * /relative/path/to/some-event.template.php |
|
| 165 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 166 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 167 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 168 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 169 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 170 | + * Had you passed an absolute path to your template that was in some other location, |
|
| 171 | + * ie: "/absolute/path/to/some-event.template.php" |
|
| 172 | + * then the search would have been : |
|
| 173 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 174 | + * /absolute/path/to/some-event.template.php |
|
| 175 | + * and stopped there upon finding it in the second location |
|
| 176 | + * |
|
| 177 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 178 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 179 | + * @param boolean $load whether to pass the located template path on to the |
|
| 180 | + * EEH_Template::display_template() method or simply return it |
|
| 181 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 182 | + * string |
|
| 183 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 184 | + * generate a custom template or not. Used in places where you don't actually |
|
| 185 | + * load the template, you just want to know if there's a custom version of it. |
|
| 186 | + * @return mixed |
|
| 187 | + */ |
|
| 188 | + public static function locate_template( |
|
| 189 | + $templates = array(), |
|
| 190 | + $template_args = array(), |
|
| 191 | + $load = true, |
|
| 192 | + $return_string = true, |
|
| 193 | + $check_if_custom = false |
|
| 194 | + ) { |
|
| 195 | + // first use WP locate_template to check for template in the current theme folder |
|
| 196 | + $template_path = locate_template($templates); |
|
| 197 | + |
|
| 198 | + if ($check_if_custom && ! empty($template_path)) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // not in the theme |
|
| 203 | + if (empty($template_path)) { |
|
| 204 | + // not even a template to look for ? |
|
| 205 | + if (empty($templates)) { |
|
| 206 | + // get post_type |
|
| 207 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
| 208 | + // get array of EE Custom Post Types |
|
| 209 | + $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
| 210 | + // build template name based on request |
|
| 211 | + if (isset($EE_CPTs[$post_type])) { |
|
| 212 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 213 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 214 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + // currently active EE template theme |
|
| 218 | + $current_theme = EE_Config::get_current_theme(); |
|
| 219 | + |
|
| 220 | + // array of paths to folders that may contain templates |
|
| 221 | + $template_folder_paths = array( |
|
| 222 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 223 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 224 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 225 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 226 | + ); |
|
| 227 | + |
|
| 228 | + //add core plugin folders for checking only if we're not $check_if_custom |
|
| 229 | + if ( ! $check_if_custom) { |
|
| 230 | + $core_paths = array( |
|
| 231 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 232 | + EE_PUBLIC . $current_theme, |
|
| 233 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 234 | + EE_TEMPLATES . $current_theme, |
|
| 235 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 236 | + EE_PLUGIN_DIR_PATH, |
|
| 237 | + ); |
|
| 238 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // now filter that array |
|
| 242 | + $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 243 | + $template_folder_paths); |
|
| 244 | + $templates = is_array($templates) ? $templates : array($templates); |
|
| 245 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
| 246 | + // array to hold all possible template paths |
|
| 247 | + $full_template_paths = array(); |
|
| 248 | + |
|
| 249 | + // loop through $templates |
|
| 250 | + foreach ($templates as $template) { |
|
| 251 | + // normalize directory separators |
|
| 252 | + $template = EEH_File::standardise_directory_separators($template); |
|
| 253 | + $file_name = basename($template); |
|
| 254 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 255 | + // while looping through all template folder paths |
|
| 256 | + foreach ($template_folder_paths as $template_folder_path) { |
|
| 257 | + // normalize directory separators |
|
| 258 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 259 | + // determine if any common base path exists between the two paths |
|
| 260 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
| 261 | + array($template_folder_path, $template_path_minus_file_name) |
|
| 262 | + ); |
|
| 263 | + if ($common_base_path !== '') { |
|
| 264 | + // both paths have a common base, so just tack the filename onto our search path |
|
| 265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 266 | + } else { |
|
| 267 | + // no common base path, so let's just concatenate |
|
| 268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 269 | + } |
|
| 270 | + // build up our template locations array by adding our resolved paths |
|
| 271 | + $full_template_paths[] = $resolved_path; |
|
| 272 | + } |
|
| 273 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 274 | + array_unshift($full_template_paths, $template); |
|
| 275 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 276 | + array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
| 277 | + } |
|
| 278 | + // filter final array of full template paths |
|
| 279 | + $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 280 | + $full_template_paths, $file_name); |
|
| 281 | + // now loop through our final array of template location paths and check each location |
|
| 282 | + foreach ((array)$full_template_paths as $full_template_path) { |
|
| 283 | + if (is_readable($full_template_path)) { |
|
| 284 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
| 285 | + // hook that can be used to display the full template path that will be used |
|
| 286 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + // if we got it and you want to see it... |
|
| 292 | + if ($template_path && $load && ! $check_if_custom) { |
|
| 293 | + if ($return_string) { |
|
| 294 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
| 295 | + } else { |
|
| 296 | + EEH_Template::display_template($template_path, $template_args, false); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * _find_common_base_path |
|
| 305 | + * given two paths, this determines if there is a common base path between the two |
|
| 306 | + * |
|
| 307 | + * @param array $paths |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + protected static function _find_common_base_path($paths) |
|
| 311 | + { |
|
| 312 | + $last_offset = 0; |
|
| 313 | + $common_base_path = ''; |
|
| 314 | + while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
| 315 | + $dir_length = $index - $last_offset + 1; |
|
| 316 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 317 | + foreach ($paths as $path) { |
|
| 318 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 319 | + return $common_base_path; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + $common_base_path .= $directory; |
|
| 323 | + $last_offset = $index + 1; |
|
| 324 | + } |
|
| 325 | + return substr($common_base_path, 0, -1); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * load and display a template |
|
| 331 | + * |
|
| 332 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 333 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 334 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
| 335 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 336 | + * not found or is not readable |
|
| 337 | + * @return mixed string |
|
| 338 | + * @throws \DomainException |
|
| 339 | + */ |
|
| 340 | 340 | public static function display_template( |
| 341 | - $template_path = false, |
|
| 342 | - $template_args = array(), |
|
| 343 | - $return_string = false, |
|
| 344 | - $throw_exceptions = false |
|
| 345 | - ) { |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 349 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 350 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
| 351 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 352 | - * using this. |
|
| 353 | - * |
|
| 354 | - * @since 4.6.0 |
|
| 355 | - */ |
|
| 356 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 357 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 358 | - |
|
| 359 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
| 360 | - if ( ! $template_path || ! is_readable($template_path)) { |
|
| 361 | - return ''; |
|
| 362 | - } |
|
| 363 | - // if $template_args are not in an array, then make it so |
|
| 364 | - if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
| 365 | - $template_args = array($template_args); |
|
| 366 | - } |
|
| 367 | - extract( $template_args, EXTR_SKIP ); |
|
| 368 | - // ignore whether template is accessible ? |
|
| 369 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
| 370 | - throw new \DomainException( |
|
| 371 | - esc_html__( |
|
| 372 | - 'Invalid, unreadable, or missing file.', |
|
| 373 | - 'event_espresso' |
|
| 374 | - ) |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - if ($return_string) { |
|
| 380 | - // because we want to return a string, we are going to capture the output |
|
| 381 | - ob_start(); |
|
| 382 | - include($template_path); |
|
| 383 | - return ob_get_clean(); |
|
| 384 | - } else { |
|
| 385 | - include($template_path); |
|
| 386 | - } |
|
| 387 | - return ''; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 393 | - * |
|
| 394 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 395 | - * @param string $prefix added to the beginning of the generated class |
|
| 396 | - * @param string $suffix added to the end of the generated class |
|
| 397 | - * @return string |
|
| 398 | - */ |
|
| 399 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 400 | - { |
|
| 401 | - // in the beginning... |
|
| 402 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 403 | - // da muddle |
|
| 404 | - $class = ''; |
|
| 405 | - // the end |
|
| 406 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 407 | - // is the passed object an EE object ? |
|
| 408 | - if ($object instanceof EE_Base_Class) { |
|
| 409 | - // grab the exact type of object |
|
| 410 | - $obj_class = get_class($object); |
|
| 411 | - // depending on the type of object... |
|
| 412 | - switch ($obj_class) { |
|
| 413 | - // no specifics just yet... |
|
| 414 | - default : |
|
| 415 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 416 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 417 | - |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - return $prefix . $class . $suffix; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * EEH_Template::format_currency |
|
| 427 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 428 | - * the country currency settings from the supplied country ISO code |
|
| 429 | - * |
|
| 430 | - * @param float $amount raw money value |
|
| 431 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 432 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 433 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 434 | - * @param string $cur_code_span_class |
|
| 435 | - * @return string the html output for the formatted money value |
|
| 436 | - * @throws \EE_Error |
|
| 437 | - */ |
|
| 438 | - public static function format_currency( |
|
| 439 | - $amount = null, |
|
| 440 | - $return_raw = false, |
|
| 441 | - $display_code = true, |
|
| 442 | - $CNT_ISO = '', |
|
| 443 | - $cur_code_span_class = 'currency-code' |
|
| 444 | - ) { |
|
| 445 | - // ensure amount was received |
|
| 446 | - if ($amount === null) { |
|
| 447 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 448 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 449 | - return ''; |
|
| 450 | - } |
|
| 451 | - //ensure amount is float |
|
| 452 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
| 453 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 454 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 455 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 456 | - // still a number or was amount converted to a string like "free" ? |
|
| 457 | - if (is_float($amount_formatted)) { |
|
| 458 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
| 459 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 460 | - // verify results |
|
| 461 | - if ( ! $mny instanceof EE_Currency_Config) { |
|
| 462 | - // set default config country currency settings |
|
| 463 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 464 | - ? EE_Registry::instance()->CFG->currency |
|
| 465 | - : new EE_Currency_Config(); |
|
| 466 | - } |
|
| 467 | - // format float |
|
| 468 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 469 | - // add formatting ? |
|
| 470 | - if ( ! $return_raw) { |
|
| 471 | - // add currency sign |
|
| 472 | - if ($mny->sign_b4) { |
|
| 473 | - if ($amount >= 0) { |
|
| 474 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 475 | - } else { |
|
| 476 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - } else { |
|
| 480 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // filter to allow global setting of display_code |
|
| 484 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
| 485 | - |
|
| 486 | - // add currency code ? |
|
| 487 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 488 | - } |
|
| 489 | - // filter results |
|
| 490 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 491 | - $amount_formatted, $mny, $return_raw); |
|
| 492 | - } |
|
| 493 | - // clean up vars |
|
| 494 | - unset($mny); |
|
| 495 | - // return formatted currency amount |
|
| 496 | - return $amount_formatted; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 502 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 503 | - * related status model or model object (i.e. in documentation etc.) |
|
| 504 | - * |
|
| 505 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 506 | - * match, then 'Unknown' will be returned. |
|
| 507 | - * @param boolean $plural Whether to return plural or not |
|
| 508 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 509 | - * @return string The localized label for the status id. |
|
| 510 | - */ |
|
| 511 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 512 | - { |
|
| 513 | - /** @type EEM_Status $EEM_Status */ |
|
| 514 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
| 515 | - $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
| 516 | - $schema); |
|
| 517 | - return $status[$status_id]; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This helper just returns a button or link for the given parameters |
|
| 523 | - * |
|
| 524 | - * @param string $url the url for the link |
|
| 525 | - * @param string $label What is the label you want displayed for the button |
|
| 526 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 527 | - * @param string $icon |
|
| 528 | - * @param string $title |
|
| 529 | - * @return string the html output for the button |
|
| 530 | - */ |
|
| 531 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
| 532 | - { |
|
| 533 | - $icon_html = ''; |
|
| 534 | - if ( ! empty($icon)) { |
|
| 535 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 536 | - $dashicons = array_filter($dashicons); |
|
| 537 | - $count = count($dashicons); |
|
| 538 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 539 | - foreach ($dashicons as $dashicon) { |
|
| 540 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 541 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 542 | - } |
|
| 543 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 544 | - } |
|
| 545 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 546 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 547 | - return $button; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * This returns a generated link that will load the related help tab on admin pages. |
|
| 553 | - * |
|
| 554 | - * @param string $help_tab_id the id for the connected help tab |
|
| 555 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
| 556 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 557 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 558 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 559 | - * @return string generated link |
|
| 560 | - */ |
|
| 561 | - public static function get_help_tab_link( |
|
| 562 | - $help_tab_id, |
|
| 563 | - $page = false, |
|
| 564 | - $action = false, |
|
| 565 | - $icon_style = false, |
|
| 566 | - $help_text = false |
|
| 567 | - ) { |
|
| 568 | - |
|
| 569 | - if ( ! $page) { |
|
| 570 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if ( ! $action) { |
|
| 574 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $action = empty($action) ? 'default' : $action; |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 581 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 582 | - $help_text = ! $help_text ? '' : $help_text; |
|
| 583 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
| 584 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 590 | - * |
|
| 591 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 592 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 593 | - * @param EE_Help_Tour |
|
| 594 | - * @return string html |
|
| 595 | - */ |
|
| 596 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 597 | - { |
|
| 598 | - $id = $tour->get_slug(); |
|
| 599 | - $stops = $tour->get_stops(); |
|
| 600 | - |
|
| 601 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 602 | - |
|
| 603 | - foreach ($stops as $stop) { |
|
| 604 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 605 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 606 | - |
|
| 607 | - //if container is set to modal then let's make sure we set the options accordingly |
|
| 608 | - if (empty($data_id) && empty($data_class)) { |
|
| 609 | - $stop['options']['modal'] = true; |
|
| 610 | - $stop['options']['expose'] = true; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 614 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 615 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
| 616 | - |
|
| 617 | - //options |
|
| 618 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 619 | - $options = ' data-options="'; |
|
| 620 | - foreach ($stop['options'] as $option => $value) { |
|
| 621 | - $options .= $option . ':' . $value . ';'; |
|
| 622 | - } |
|
| 623 | - $options .= '"'; |
|
| 624 | - } else { |
|
| 625 | - $options = ''; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - //let's put all together |
|
| 629 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - $content .= '</ol>'; |
|
| 633 | - return $content; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * This is a helper method to generate a status legend for a given status array. |
|
| 639 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 640 | - * status_array. |
|
| 641 | - * |
|
| 642 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 643 | - * array( |
|
| 644 | - * 'status_item' => 'status_name' |
|
| 645 | - * ) |
|
| 646 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 647 | - * the legend. |
|
| 648 | - * @throws EE_Error |
|
| 649 | - * @return string html structure for status. |
|
| 650 | - */ |
|
| 651 | - public static function status_legend($status_array, $active_status = '') |
|
| 652 | - { |
|
| 653 | - if ( ! is_array($status_array)) { |
|
| 654 | - throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 655 | - 'event_espresso')); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - $setup_array = array(); |
|
| 659 | - foreach ($status_array as $item => $status) { |
|
| 660 | - $setup_array[$item] = array( |
|
| 661 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 662 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 663 | - 'status' => $status, |
|
| 664 | - ); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 668 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 669 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 670 | - foreach ($setup_array as $item => $details) { |
|
| 671 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
| 672 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 673 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 674 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 675 | - $content .= '</dt>' . "\n"; |
|
| 676 | - } |
|
| 677 | - $content .= '</dl>' . "\n"; |
|
| 678 | - $content .= '</div>' . "\n"; |
|
| 679 | - return $content; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 685 | - * that's nice for presenting in the wp admin |
|
| 686 | - * |
|
| 687 | - * @param mixed $data |
|
| 688 | - * @return string |
|
| 689 | - */ |
|
| 690 | - public static function layout_array_as_table($data) |
|
| 691 | - { |
|
| 692 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 693 | - $data = (array)$data; |
|
| 694 | - } |
|
| 695 | - ob_start(); |
|
| 696 | - if (is_array($data)) { |
|
| 697 | - if (EEH_Array::is_associative_array($data)) { |
|
| 698 | - ?> |
|
| 341 | + $template_path = false, |
|
| 342 | + $template_args = array(), |
|
| 343 | + $return_string = false, |
|
| 344 | + $throw_exceptions = false |
|
| 345 | + ) { |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 349 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 350 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
| 351 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 352 | + * using this. |
|
| 353 | + * |
|
| 354 | + * @since 4.6.0 |
|
| 355 | + */ |
|
| 356 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 357 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 358 | + |
|
| 359 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
| 360 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
| 361 | + return ''; |
|
| 362 | + } |
|
| 363 | + // if $template_args are not in an array, then make it so |
|
| 364 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
| 365 | + $template_args = array($template_args); |
|
| 366 | + } |
|
| 367 | + extract( $template_args, EXTR_SKIP ); |
|
| 368 | + // ignore whether template is accessible ? |
|
| 369 | + if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
| 370 | + throw new \DomainException( |
|
| 371 | + esc_html__( |
|
| 372 | + 'Invalid, unreadable, or missing file.', |
|
| 373 | + 'event_espresso' |
|
| 374 | + ) |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + if ($return_string) { |
|
| 380 | + // because we want to return a string, we are going to capture the output |
|
| 381 | + ob_start(); |
|
| 382 | + include($template_path); |
|
| 383 | + return ob_get_clean(); |
|
| 384 | + } else { |
|
| 385 | + include($template_path); |
|
| 386 | + } |
|
| 387 | + return ''; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 393 | + * |
|
| 394 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 395 | + * @param string $prefix added to the beginning of the generated class |
|
| 396 | + * @param string $suffix added to the end of the generated class |
|
| 397 | + * @return string |
|
| 398 | + */ |
|
| 399 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 400 | + { |
|
| 401 | + // in the beginning... |
|
| 402 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 403 | + // da muddle |
|
| 404 | + $class = ''; |
|
| 405 | + // the end |
|
| 406 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 407 | + // is the passed object an EE object ? |
|
| 408 | + if ($object instanceof EE_Base_Class) { |
|
| 409 | + // grab the exact type of object |
|
| 410 | + $obj_class = get_class($object); |
|
| 411 | + // depending on the type of object... |
|
| 412 | + switch ($obj_class) { |
|
| 413 | + // no specifics just yet... |
|
| 414 | + default : |
|
| 415 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 416 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 417 | + |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + return $prefix . $class . $suffix; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * EEH_Template::format_currency |
|
| 427 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 428 | + * the country currency settings from the supplied country ISO code |
|
| 429 | + * |
|
| 430 | + * @param float $amount raw money value |
|
| 431 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 432 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 433 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 434 | + * @param string $cur_code_span_class |
|
| 435 | + * @return string the html output for the formatted money value |
|
| 436 | + * @throws \EE_Error |
|
| 437 | + */ |
|
| 438 | + public static function format_currency( |
|
| 439 | + $amount = null, |
|
| 440 | + $return_raw = false, |
|
| 441 | + $display_code = true, |
|
| 442 | + $CNT_ISO = '', |
|
| 443 | + $cur_code_span_class = 'currency-code' |
|
| 444 | + ) { |
|
| 445 | + // ensure amount was received |
|
| 446 | + if ($amount === null) { |
|
| 447 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 448 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 449 | + return ''; |
|
| 450 | + } |
|
| 451 | + //ensure amount is float |
|
| 452 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
| 453 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 454 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 455 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 456 | + // still a number or was amount converted to a string like "free" ? |
|
| 457 | + if (is_float($amount_formatted)) { |
|
| 458 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
| 459 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 460 | + // verify results |
|
| 461 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
| 462 | + // set default config country currency settings |
|
| 463 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 464 | + ? EE_Registry::instance()->CFG->currency |
|
| 465 | + : new EE_Currency_Config(); |
|
| 466 | + } |
|
| 467 | + // format float |
|
| 468 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 469 | + // add formatting ? |
|
| 470 | + if ( ! $return_raw) { |
|
| 471 | + // add currency sign |
|
| 472 | + if ($mny->sign_b4) { |
|
| 473 | + if ($amount >= 0) { |
|
| 474 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
| 475 | + } else { |
|
| 476 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + } else { |
|
| 480 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // filter to allow global setting of display_code |
|
| 484 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
| 485 | + |
|
| 486 | + // add currency code ? |
|
| 487 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 488 | + } |
|
| 489 | + // filter results |
|
| 490 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 491 | + $amount_formatted, $mny, $return_raw); |
|
| 492 | + } |
|
| 493 | + // clean up vars |
|
| 494 | + unset($mny); |
|
| 495 | + // return formatted currency amount |
|
| 496 | + return $amount_formatted; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 502 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 503 | + * related status model or model object (i.e. in documentation etc.) |
|
| 504 | + * |
|
| 505 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 506 | + * match, then 'Unknown' will be returned. |
|
| 507 | + * @param boolean $plural Whether to return plural or not |
|
| 508 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 509 | + * @return string The localized label for the status id. |
|
| 510 | + */ |
|
| 511 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 512 | + { |
|
| 513 | + /** @type EEM_Status $EEM_Status */ |
|
| 514 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
| 515 | + $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
| 516 | + $schema); |
|
| 517 | + return $status[$status_id]; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This helper just returns a button or link for the given parameters |
|
| 523 | + * |
|
| 524 | + * @param string $url the url for the link |
|
| 525 | + * @param string $label What is the label you want displayed for the button |
|
| 526 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 527 | + * @param string $icon |
|
| 528 | + * @param string $title |
|
| 529 | + * @return string the html output for the button |
|
| 530 | + */ |
|
| 531 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
| 532 | + { |
|
| 533 | + $icon_html = ''; |
|
| 534 | + if ( ! empty($icon)) { |
|
| 535 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 536 | + $dashicons = array_filter($dashicons); |
|
| 537 | + $count = count($dashicons); |
|
| 538 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 539 | + foreach ($dashicons as $dashicon) { |
|
| 540 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 541 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 542 | + } |
|
| 543 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 544 | + } |
|
| 545 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 546 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 547 | + return $button; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * This returns a generated link that will load the related help tab on admin pages. |
|
| 553 | + * |
|
| 554 | + * @param string $help_tab_id the id for the connected help tab |
|
| 555 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
| 556 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 557 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 558 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 559 | + * @return string generated link |
|
| 560 | + */ |
|
| 561 | + public static function get_help_tab_link( |
|
| 562 | + $help_tab_id, |
|
| 563 | + $page = false, |
|
| 564 | + $action = false, |
|
| 565 | + $icon_style = false, |
|
| 566 | + $help_text = false |
|
| 567 | + ) { |
|
| 568 | + |
|
| 569 | + if ( ! $page) { |
|
| 570 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if ( ! $action) { |
|
| 574 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $action = empty($action) ? 'default' : $action; |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 581 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 582 | + $help_text = ! $help_text ? '' : $help_text; |
|
| 583 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
| 584 | + 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 590 | + * |
|
| 591 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 592 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 593 | + * @param EE_Help_Tour |
|
| 594 | + * @return string html |
|
| 595 | + */ |
|
| 596 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 597 | + { |
|
| 598 | + $id = $tour->get_slug(); |
|
| 599 | + $stops = $tour->get_stops(); |
|
| 600 | + |
|
| 601 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 602 | + |
|
| 603 | + foreach ($stops as $stop) { |
|
| 604 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 605 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 606 | + |
|
| 607 | + //if container is set to modal then let's make sure we set the options accordingly |
|
| 608 | + if (empty($data_id) && empty($data_class)) { |
|
| 609 | + $stop['options']['modal'] = true; |
|
| 610 | + $stop['options']['expose'] = true; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 614 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 615 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
| 616 | + |
|
| 617 | + //options |
|
| 618 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 619 | + $options = ' data-options="'; |
|
| 620 | + foreach ($stop['options'] as $option => $value) { |
|
| 621 | + $options .= $option . ':' . $value . ';'; |
|
| 622 | + } |
|
| 623 | + $options .= '"'; |
|
| 624 | + } else { |
|
| 625 | + $options = ''; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + //let's put all together |
|
| 629 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + $content .= '</ol>'; |
|
| 633 | + return $content; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * This is a helper method to generate a status legend for a given status array. |
|
| 639 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 640 | + * status_array. |
|
| 641 | + * |
|
| 642 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 643 | + * array( |
|
| 644 | + * 'status_item' => 'status_name' |
|
| 645 | + * ) |
|
| 646 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 647 | + * the legend. |
|
| 648 | + * @throws EE_Error |
|
| 649 | + * @return string html structure for status. |
|
| 650 | + */ |
|
| 651 | + public static function status_legend($status_array, $active_status = '') |
|
| 652 | + { |
|
| 653 | + if ( ! is_array($status_array)) { |
|
| 654 | + throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 655 | + 'event_espresso')); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + $setup_array = array(); |
|
| 659 | + foreach ($status_array as $item => $status) { |
|
| 660 | + $setup_array[$item] = array( |
|
| 661 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 662 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 663 | + 'status' => $status, |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 668 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 669 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 670 | + foreach ($setup_array as $item => $details) { |
|
| 671 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
| 672 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 673 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 674 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 675 | + $content .= '</dt>' . "\n"; |
|
| 676 | + } |
|
| 677 | + $content .= '</dl>' . "\n"; |
|
| 678 | + $content .= '</div>' . "\n"; |
|
| 679 | + return $content; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 685 | + * that's nice for presenting in the wp admin |
|
| 686 | + * |
|
| 687 | + * @param mixed $data |
|
| 688 | + * @return string |
|
| 689 | + */ |
|
| 690 | + public static function layout_array_as_table($data) |
|
| 691 | + { |
|
| 692 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 693 | + $data = (array)$data; |
|
| 694 | + } |
|
| 695 | + ob_start(); |
|
| 696 | + if (is_array($data)) { |
|
| 697 | + if (EEH_Array::is_associative_array($data)) { |
|
| 698 | + ?> |
|
| 699 | 699 | <table class="widefat"> |
| 700 | 700 | <tbody> |
| 701 | 701 | <?php |
| 702 | - foreach ($data as $data_key => $data_values) { |
|
| 703 | - ?> |
|
| 702 | + foreach ($data as $data_key => $data_values) { |
|
| 703 | + ?> |
|
| 704 | 704 | <tr> |
| 705 | 705 | <td> |
| 706 | 706 | <?php echo $data_key; ?> |
@@ -710,248 +710,248 @@ discard block |
||
| 710 | 710 | </td> |
| 711 | 711 | </tr> |
| 712 | 712 | <?php |
| 713 | - } ?> |
|
| 713 | + } ?> |
|
| 714 | 714 | </tbody> |
| 715 | 715 | </table> |
| 716 | 716 | <?php |
| 717 | - } else { |
|
| 718 | - ?> |
|
| 717 | + } else { |
|
| 718 | + ?> |
|
| 719 | 719 | <ul> |
| 720 | 720 | <?php |
| 721 | - foreach ($data as $datum) { |
|
| 722 | - echo "<li>"; |
|
| 723 | - echo self::layout_array_as_table($datum); |
|
| 724 | - echo "</li>"; |
|
| 725 | - } ?> |
|
| 721 | + foreach ($data as $datum) { |
|
| 722 | + echo "<li>"; |
|
| 723 | + echo self::layout_array_as_table($datum); |
|
| 724 | + echo "</li>"; |
|
| 725 | + } ?> |
|
| 726 | 726 | </ul> |
| 727 | 727 | <?php |
| 728 | - } |
|
| 729 | - } else { |
|
| 730 | - //simple value |
|
| 731 | - echo esc_html($data); |
|
| 732 | - } |
|
| 733 | - return ob_get_clean(); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 739 | - * |
|
| 740 | - * @since 4.4.0 |
|
| 741 | - * @see self:get_paging_html() for argument docs. |
|
| 742 | - * @param $total_items |
|
| 743 | - * @param $current |
|
| 744 | - * @param $per_page |
|
| 745 | - * @param $url |
|
| 746 | - * @param bool $show_num_field |
|
| 747 | - * @param string $paged_arg_name |
|
| 748 | - * @param array $items_label |
|
| 749 | - * @return string |
|
| 750 | - */ |
|
| 751 | - public static function paging_html( |
|
| 752 | - $total_items, |
|
| 753 | - $current, |
|
| 754 | - $per_page, |
|
| 755 | - $url, |
|
| 756 | - $show_num_field = true, |
|
| 757 | - $paged_arg_name = 'paged', |
|
| 758 | - $items_label = array() |
|
| 759 | - ) { |
|
| 760 | - echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
| 761 | - $items_label); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * A method for generating paging similar to WP_List_Table |
|
| 767 | - * |
|
| 768 | - * @since 4.4.0 |
|
| 769 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 770 | - * @param integer $total_items How many total items there are to page. |
|
| 771 | - * @param integer $current What the current page is. |
|
| 772 | - * @param integer $per_page How many items per page. |
|
| 773 | - * @param string $url What the base url for page links is. |
|
| 774 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 775 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 776 | - * @param array $items_label An array of singular/plural values for the items label: |
|
| 777 | - * array( |
|
| 778 | - * 'single' => 'item', |
|
| 779 | - * 'plural' => 'items' |
|
| 780 | - * ) |
|
| 781 | - * @return string |
|
| 782 | - */ |
|
| 783 | - public static function get_paging_html( |
|
| 784 | - $total_items, |
|
| 785 | - $current, |
|
| 786 | - $per_page, |
|
| 787 | - $url, |
|
| 788 | - $show_num_field = true, |
|
| 789 | - $paged_arg_name = 'paged', |
|
| 790 | - $items_label = array() |
|
| 791 | - ) { |
|
| 792 | - $page_links = array(); |
|
| 793 | - $disable_first = $disable_last = ''; |
|
| 794 | - $total_items = (int)$total_items; |
|
| 795 | - $per_page = (int)$per_page; |
|
| 796 | - $current = (int)$current; |
|
| 797 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 798 | - |
|
| 799 | - //filter items_label |
|
| 800 | - $items_label = apply_filters( |
|
| 801 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 802 | - $items_label |
|
| 803 | - ); |
|
| 804 | - |
|
| 805 | - if (empty($items_label) |
|
| 806 | - || ! is_array($items_label) |
|
| 807 | - || ! isset($items_label['single']) |
|
| 808 | - || ! isset($items_label['plural']) |
|
| 809 | - ) { |
|
| 810 | - $items_label = array( |
|
| 811 | - 'single' => __('1 item', 'event_espresso'), |
|
| 812 | - 'plural' => __('%s items', 'event_espresso'), |
|
| 813 | - ); |
|
| 814 | - } else { |
|
| 815 | - $items_label = array( |
|
| 816 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 817 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 818 | - ); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - $total_pages = ceil($total_items / $per_page); |
|
| 822 | - |
|
| 823 | - if ($total_pages <= 1) { |
|
| 824 | - return ''; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 828 | - |
|
| 829 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 830 | - |
|
| 831 | - if ($current === 1) { |
|
| 832 | - $disable_first = ' disabled'; |
|
| 833 | - } |
|
| 834 | - if ($current == $total_pages) { |
|
| 835 | - $disable_last = ' disabled'; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 839 | - 'first-page' . $disable_first, |
|
| 840 | - esc_attr__('Go to the first page'), |
|
| 841 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
| 842 | - '«' |
|
| 843 | - ); |
|
| 844 | - |
|
| 845 | - $page_links[] = sprintf( |
|
| 846 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 847 | - 'prev-page' . $disable_first, |
|
| 848 | - esc_attr__('Go to the previous page'), |
|
| 849 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 850 | - '‹' |
|
| 851 | - ); |
|
| 852 | - |
|
| 853 | - if ( ! $show_num_field) { |
|
| 854 | - $html_current_page = $current; |
|
| 855 | - } else { |
|
| 856 | - $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 857 | - esc_attr__('Current page'), |
|
| 858 | - $current, |
|
| 859 | - strlen($total_pages) |
|
| 860 | - ); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - $html_total_pages = sprintf( |
|
| 864 | - '<span class="total-pages">%s</span>', |
|
| 865 | - number_format_i18n($total_pages) |
|
| 866 | - ); |
|
| 867 | - $page_links[] = sprintf( |
|
| 868 | - _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
| 869 | - $html_current_page, |
|
| 870 | - $html_total_pages, |
|
| 871 | - '<span class="paging-input">', |
|
| 872 | - '</span>' |
|
| 873 | - ); |
|
| 874 | - |
|
| 875 | - $page_links[] = sprintf( |
|
| 876 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 877 | - 'next-page' . $disable_last, |
|
| 878 | - esc_attr__('Go to the next page'), |
|
| 879 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 880 | - '›' |
|
| 881 | - ); |
|
| 882 | - |
|
| 883 | - $page_links[] = sprintf( |
|
| 884 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 885 | - 'last-page' . $disable_last, |
|
| 886 | - esc_attr__('Go to the last page'), |
|
| 887 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 888 | - '»' |
|
| 889 | - ); |
|
| 890 | - |
|
| 891 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 892 | - // set page class |
|
| 893 | - if ($total_pages) { |
|
| 894 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 895 | - } else { |
|
| 896 | - $page_class = ' no-pages'; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * @param string $wrap_class |
|
| 905 | - * @param string $wrap_id |
|
| 906 | - * @return string |
|
| 907 | - */ |
|
| 908 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
| 909 | - { |
|
| 910 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 911 | - if ( |
|
| 912 | - ! $admin && |
|
| 913 | - ! apply_filters( |
|
| 914 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 915 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 916 | - ) |
|
| 917 | - ) { |
|
| 918 | - return ''; |
|
| 919 | - } |
|
| 920 | - $tag = $admin ? 'span' : 'div'; |
|
| 921 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 922 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 923 | - $attributes .= ! empty($wrap_class) |
|
| 924 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 925 | - : ' class="powered-by-event-espresso-credit"'; |
|
| 926 | - $query_args = array_merge( |
|
| 927 | - array( |
|
| 928 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 929 | - 'utm_source' => 'powered_by_event_espresso', |
|
| 930 | - 'utm_medium' => 'link', |
|
| 931 | - 'utm_campaign' => 'powered_by', |
|
| 932 | - ), |
|
| 933 | - $query_args |
|
| 934 | - ); |
|
| 935 | - $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 936 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
| 937 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 938 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 939 | - return (string)apply_filters( |
|
| 940 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 941 | - sprintf( |
|
| 942 | - esc_html_x( |
|
| 943 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 944 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 945 | - 'event_espresso' |
|
| 946 | - ), |
|
| 947 | - "<{$tag}{$attributes}>", |
|
| 948 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 949 | - $admin ? '' : '<br />' |
|
| 950 | - ), |
|
| 951 | - $wrap_class, |
|
| 952 | - $wrap_id |
|
| 953 | - ); |
|
| 954 | - } |
|
| 728 | + } |
|
| 729 | + } else { |
|
| 730 | + //simple value |
|
| 731 | + echo esc_html($data); |
|
| 732 | + } |
|
| 733 | + return ob_get_clean(); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 739 | + * |
|
| 740 | + * @since 4.4.0 |
|
| 741 | + * @see self:get_paging_html() for argument docs. |
|
| 742 | + * @param $total_items |
|
| 743 | + * @param $current |
|
| 744 | + * @param $per_page |
|
| 745 | + * @param $url |
|
| 746 | + * @param bool $show_num_field |
|
| 747 | + * @param string $paged_arg_name |
|
| 748 | + * @param array $items_label |
|
| 749 | + * @return string |
|
| 750 | + */ |
|
| 751 | + public static function paging_html( |
|
| 752 | + $total_items, |
|
| 753 | + $current, |
|
| 754 | + $per_page, |
|
| 755 | + $url, |
|
| 756 | + $show_num_field = true, |
|
| 757 | + $paged_arg_name = 'paged', |
|
| 758 | + $items_label = array() |
|
| 759 | + ) { |
|
| 760 | + echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
| 761 | + $items_label); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * A method for generating paging similar to WP_List_Table |
|
| 767 | + * |
|
| 768 | + * @since 4.4.0 |
|
| 769 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 770 | + * @param integer $total_items How many total items there are to page. |
|
| 771 | + * @param integer $current What the current page is. |
|
| 772 | + * @param integer $per_page How many items per page. |
|
| 773 | + * @param string $url What the base url for page links is. |
|
| 774 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 775 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 776 | + * @param array $items_label An array of singular/plural values for the items label: |
|
| 777 | + * array( |
|
| 778 | + * 'single' => 'item', |
|
| 779 | + * 'plural' => 'items' |
|
| 780 | + * ) |
|
| 781 | + * @return string |
|
| 782 | + */ |
|
| 783 | + public static function get_paging_html( |
|
| 784 | + $total_items, |
|
| 785 | + $current, |
|
| 786 | + $per_page, |
|
| 787 | + $url, |
|
| 788 | + $show_num_field = true, |
|
| 789 | + $paged_arg_name = 'paged', |
|
| 790 | + $items_label = array() |
|
| 791 | + ) { |
|
| 792 | + $page_links = array(); |
|
| 793 | + $disable_first = $disable_last = ''; |
|
| 794 | + $total_items = (int)$total_items; |
|
| 795 | + $per_page = (int)$per_page; |
|
| 796 | + $current = (int)$current; |
|
| 797 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 798 | + |
|
| 799 | + //filter items_label |
|
| 800 | + $items_label = apply_filters( |
|
| 801 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 802 | + $items_label |
|
| 803 | + ); |
|
| 804 | + |
|
| 805 | + if (empty($items_label) |
|
| 806 | + || ! is_array($items_label) |
|
| 807 | + || ! isset($items_label['single']) |
|
| 808 | + || ! isset($items_label['plural']) |
|
| 809 | + ) { |
|
| 810 | + $items_label = array( |
|
| 811 | + 'single' => __('1 item', 'event_espresso'), |
|
| 812 | + 'plural' => __('%s items', 'event_espresso'), |
|
| 813 | + ); |
|
| 814 | + } else { |
|
| 815 | + $items_label = array( |
|
| 816 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
| 817 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 818 | + ); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + $total_pages = ceil($total_items / $per_page); |
|
| 822 | + |
|
| 823 | + if ($total_pages <= 1) { |
|
| 824 | + return ''; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 828 | + |
|
| 829 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 830 | + |
|
| 831 | + if ($current === 1) { |
|
| 832 | + $disable_first = ' disabled'; |
|
| 833 | + } |
|
| 834 | + if ($current == $total_pages) { |
|
| 835 | + $disable_last = ' disabled'; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 839 | + 'first-page' . $disable_first, |
|
| 840 | + esc_attr__('Go to the first page'), |
|
| 841 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
| 842 | + '«' |
|
| 843 | + ); |
|
| 844 | + |
|
| 845 | + $page_links[] = sprintf( |
|
| 846 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 847 | + 'prev-page' . $disable_first, |
|
| 848 | + esc_attr__('Go to the previous page'), |
|
| 849 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 850 | + '‹' |
|
| 851 | + ); |
|
| 852 | + |
|
| 853 | + if ( ! $show_num_field) { |
|
| 854 | + $html_current_page = $current; |
|
| 855 | + } else { |
|
| 856 | + $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 857 | + esc_attr__('Current page'), |
|
| 858 | + $current, |
|
| 859 | + strlen($total_pages) |
|
| 860 | + ); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + $html_total_pages = sprintf( |
|
| 864 | + '<span class="total-pages">%s</span>', |
|
| 865 | + number_format_i18n($total_pages) |
|
| 866 | + ); |
|
| 867 | + $page_links[] = sprintf( |
|
| 868 | + _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
| 869 | + $html_current_page, |
|
| 870 | + $html_total_pages, |
|
| 871 | + '<span class="paging-input">', |
|
| 872 | + '</span>' |
|
| 873 | + ); |
|
| 874 | + |
|
| 875 | + $page_links[] = sprintf( |
|
| 876 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 877 | + 'next-page' . $disable_last, |
|
| 878 | + esc_attr__('Go to the next page'), |
|
| 879 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 880 | + '›' |
|
| 881 | + ); |
|
| 882 | + |
|
| 883 | + $page_links[] = sprintf( |
|
| 884 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 885 | + 'last-page' . $disable_last, |
|
| 886 | + esc_attr__('Go to the last page'), |
|
| 887 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 888 | + '»' |
|
| 889 | + ); |
|
| 890 | + |
|
| 891 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 892 | + // set page class |
|
| 893 | + if ($total_pages) { |
|
| 894 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 895 | + } else { |
|
| 896 | + $page_class = ' no-pages'; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * @param string $wrap_class |
|
| 905 | + * @param string $wrap_id |
|
| 906 | + * @return string |
|
| 907 | + */ |
|
| 908 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
| 909 | + { |
|
| 910 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 911 | + if ( |
|
| 912 | + ! $admin && |
|
| 913 | + ! apply_filters( |
|
| 914 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 915 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 916 | + ) |
|
| 917 | + ) { |
|
| 918 | + return ''; |
|
| 919 | + } |
|
| 920 | + $tag = $admin ? 'span' : 'div'; |
|
| 921 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 922 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 923 | + $attributes .= ! empty($wrap_class) |
|
| 924 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 925 | + : ' class="powered-by-event-espresso-credit"'; |
|
| 926 | + $query_args = array_merge( |
|
| 927 | + array( |
|
| 928 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 929 | + 'utm_source' => 'powered_by_event_espresso', |
|
| 930 | + 'utm_medium' => 'link', |
|
| 931 | + 'utm_campaign' => 'powered_by', |
|
| 932 | + ), |
|
| 933 | + $query_args |
|
| 934 | + ); |
|
| 935 | + $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 936 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
| 937 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 938 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 939 | + return (string)apply_filters( |
|
| 940 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 941 | + sprintf( |
|
| 942 | + esc_html_x( |
|
| 943 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 944 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 945 | + 'event_espresso' |
|
| 946 | + ), |
|
| 947 | + "<{$tag}{$attributes}>", |
|
| 948 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 949 | + $admin ? '' : '<br />' |
|
| 950 | + ), |
|
| 951 | + $wrap_class, |
|
| 952 | + $wrap_id |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | 955 | |
| 956 | 956 | |
| 957 | 957 | } //end EEH_Template class |
@@ -960,33 +960,33 @@ discard block |
||
| 960 | 960 | |
| 961 | 961 | |
| 962 | 962 | if ( ! function_exists('espresso_pagination')) { |
| 963 | - /** |
|
| 964 | - * espresso_pagination |
|
| 965 | - * |
|
| 966 | - * @access public |
|
| 967 | - * @return void |
|
| 968 | - */ |
|
| 969 | - function espresso_pagination() |
|
| 970 | - { |
|
| 971 | - global $wp_query; |
|
| 972 | - $big = 999999999; // need an unlikely integer |
|
| 973 | - $pagination = paginate_links( |
|
| 974 | - array( |
|
| 975 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 976 | - 'format' => '?paged=%#%', |
|
| 977 | - 'current' => max(1, get_query_var('paged')), |
|
| 978 | - 'total' => $wp_query->max_num_pages, |
|
| 979 | - 'show_all' => true, |
|
| 980 | - 'end_size' => 10, |
|
| 981 | - 'mid_size' => 6, |
|
| 982 | - 'prev_next' => true, |
|
| 983 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
| 984 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
| 985 | - 'type' => 'plain', |
|
| 986 | - 'add_args' => false, |
|
| 987 | - 'add_fragment' => '', |
|
| 988 | - ) |
|
| 989 | - ); |
|
| 990 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
| 991 | - } |
|
| 963 | + /** |
|
| 964 | + * espresso_pagination |
|
| 965 | + * |
|
| 966 | + * @access public |
|
| 967 | + * @return void |
|
| 968 | + */ |
|
| 969 | + function espresso_pagination() |
|
| 970 | + { |
|
| 971 | + global $wp_query; |
|
| 972 | + $big = 999999999; // need an unlikely integer |
|
| 973 | + $pagination = paginate_links( |
|
| 974 | + array( |
|
| 975 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 976 | + 'format' => '?paged=%#%', |
|
| 977 | + 'current' => max(1, get_query_var('paged')), |
|
| 978 | + 'total' => $wp_query->max_num_pages, |
|
| 979 | + 'show_all' => true, |
|
| 980 | + 'end_size' => 10, |
|
| 981 | + 'mid_size' => 6, |
|
| 982 | + 'prev_next' => true, |
|
| 983 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
| 984 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
| 985 | + 'type' => 'plain', |
|
| 986 | + 'add_args' => false, |
|
| 987 | + 'add_fragment' => '', |
|
| 988 | + ) |
|
| 989 | + ); |
|
| 990 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
| 991 | + } |
|
| 992 | 992 | } |
| 993 | 993 | \ No newline at end of file |
@@ -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 | /** |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | public static function load_espresso_theme_functions() |
| 82 | 82 | { |
| 83 | 83 | if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
| 84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
| 85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
| 84 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) { |
|
| 85 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php'); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | public static function get_espresso_themes() |
| 97 | 97 | { |
| 98 | 98 | if (empty(EEH_Template::$_espresso_themes)) { |
| 99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 99 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
| 100 | 100 | if (empty($espresso_themes)) { |
| 101 | 101 | return array(); |
| 102 | 102 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ) { |
| 133 | 133 | do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
| 134 | 134 | $templates = array(); |
| 135 | - $name = (string)$name; |
|
| 135 | + $name = (string) $name; |
|
| 136 | 136 | if ($name != '') { |
| 137 | 137 | $templates[] = "{$slug}-{$name}.php"; |
| 138 | 138 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | if (isset($EE_CPTs[$post_type])) { |
| 212 | 212 | $archive_or_single = is_archive() ? 'archive' : ''; |
| 213 | 213 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
| 214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 214 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | // currently active EE template theme |
@@ -220,18 +220,18 @@ discard block |
||
| 220 | 220 | // array of paths to folders that may contain templates |
| 221 | 221 | $template_folder_paths = array( |
| 222 | 222 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
| 223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 223 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
| 224 | 224 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
| 225 | 225 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 226 | 226 | ); |
| 227 | 227 | |
| 228 | 228 | //add core plugin folders for checking only if we're not $check_if_custom |
| 229 | 229 | if ( ! $check_if_custom) { |
| 230 | - $core_paths = array( |
|
| 230 | + $core_paths = array( |
|
| 231 | 231 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
| 232 | - EE_PUBLIC . $current_theme, |
|
| 232 | + EE_PUBLIC.$current_theme, |
|
| 233 | 233 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
| 234 | - EE_TEMPLATES . $current_theme, |
|
| 234 | + EE_TEMPLATES.$current_theme, |
|
| 235 | 235 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
| 236 | 236 | EE_PLUGIN_DIR_PATH, |
| 237 | 237 | ); |
@@ -262,10 +262,10 @@ discard block |
||
| 262 | 262 | ); |
| 263 | 263 | if ($common_base_path !== '') { |
| 264 | 264 | // both paths have a common base, so just tack the filename onto our search path |
| 265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
| 266 | 266 | } else { |
| 267 | 267 | // no common base path, so let's just concatenate |
| 268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
| 269 | 269 | } |
| 270 | 270 | // build up our template locations array by adding our resolved paths |
| 271 | 271 | $full_template_paths[] = $resolved_path; |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
| 274 | 274 | array_unshift($full_template_paths, $template); |
| 275 | 275 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
| 276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
| 276 | + array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name); |
|
| 277 | 277 | } |
| 278 | 278 | // filter final array of full template paths |
| 279 | 279 | $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
| 280 | 280 | $full_template_paths, $file_name); |
| 281 | 281 | // now loop through our final array of template location paths and check each location |
| 282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
| 282 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
| 283 | 283 | if (is_readable($full_template_path)) { |
| 284 | 284 | $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
| 285 | 285 | // hook that can be used to display the full template path that will be used |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | if ( ! is_array($template_args) && ! is_object($template_args)) { |
| 365 | 365 | $template_args = array($template_args); |
| 366 | 366 | } |
| 367 | - extract( $template_args, EXTR_SKIP ); |
|
| 367 | + extract($template_args, EXTR_SKIP); |
|
| 368 | 368 | // ignore whether template is accessible ? |
| 369 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
| 369 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
| 370 | 370 | throw new \DomainException( |
| 371 | 371 | esc_html__( |
| 372 | 372 | 'Invalid, unreadable, or missing file.', |
@@ -399,11 +399,11 @@ discard block |
||
| 399 | 399 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
| 400 | 400 | { |
| 401 | 401 | // in the beginning... |
| 402 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 402 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
| 403 | 403 | // da muddle |
| 404 | 404 | $class = ''; |
| 405 | 405 | // the end |
| 406 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 406 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
| 407 | 407 | // is the passed object an EE object ? |
| 408 | 408 | if ($object instanceof EE_Base_Class) { |
| 409 | 409 | // grab the exact type of object |
@@ -413,11 +413,11 @@ discard block |
||
| 413 | 413 | // no specifics just yet... |
| 414 | 414 | default : |
| 415 | 415 | $class = strtolower(str_replace('_', '-', $obj_class)); |
| 416 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 416 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
| 417 | 417 | |
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | - return $prefix . $class . $suffix; |
|
| 420 | + return $prefix.$class.$suffix; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | return ''; |
| 450 | 450 | } |
| 451 | 451 | //ensure amount is float |
| 452 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
| 452 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 453 | 453 | $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
| 454 | 454 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
| 455 | 455 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
@@ -471,20 +471,20 @@ discard block |
||
| 471 | 471 | // add currency sign |
| 472 | 472 | if ($mny->sign_b4) { |
| 473 | 473 | if ($amount >= 0) { |
| 474 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 474 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
| 475 | 475 | } else { |
| 476 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 476 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | } else { |
| 480 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 480 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // filter to allow global setting of display_code |
| 484 | 484 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
| 485 | 485 | |
| 486 | 486 | // add currency code ? |
| 487 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 487 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
| 488 | 488 | } |
| 489 | 489 | // filter results |
| 490 | 490 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
@@ -538,12 +538,12 @@ discard block |
||
| 538 | 538 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
| 539 | 539 | foreach ($dashicons as $dashicon) { |
| 540 | 540 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
| 541 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 541 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
| 542 | 542 | } |
| 543 | 543 | $icon_html .= $count > 1 ? '</span>' : ''; |
| 544 | 544 | } |
| 545 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 546 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 545 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
| 546 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.$url.'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
| 547 | 547 | return $button; |
| 548 | 548 | } |
| 549 | 549 | |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | $action = empty($action) ? 'default' : $action; |
| 578 | 578 | |
| 579 | 579 | |
| 580 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 580 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
| 581 | 581 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
| 582 | 582 | $help_text = ! $help_text ? '' : $help_text; |
| 583 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
| 584 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
| 583 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
| 584 | + 'event_espresso').'" > '.$help_text.' </a>'; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | |
@@ -598,11 +598,11 @@ discard block |
||
| 598 | 598 | $id = $tour->get_slug(); |
| 599 | 599 | $stops = $tour->get_stops(); |
| 600 | 600 | |
| 601 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 601 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
| 602 | 602 | |
| 603 | 603 | foreach ($stops as $stop) { |
| 604 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 605 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 604 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
| 605 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
| 606 | 606 | |
| 607 | 607 | //if container is set to modal then let's make sure we set the options accordingly |
| 608 | 608 | if (empty($data_id) && empty($data_class)) { |
@@ -610,15 +610,15 @@ discard block |
||
| 610 | 610 | $stop['options']['expose'] = true; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 614 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 613 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
| 614 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
| 615 | 615 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
| 616 | 616 | |
| 617 | 617 | //options |
| 618 | 618 | if (isset($stop['options']) && is_array($stop['options'])) { |
| 619 | 619 | $options = ' data-options="'; |
| 620 | 620 | foreach ($stop['options'] as $option => $value) { |
| 621 | - $options .= $option . ':' . $value . ';'; |
|
| 621 | + $options .= $option.':'.$value.';'; |
|
| 622 | 622 | } |
| 623 | 623 | $options .= '"'; |
| 624 | 624 | } else { |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | //let's put all together |
| 629 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 629 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | $content .= '</ol>'; |
@@ -658,24 +658,24 @@ discard block |
||
| 658 | 658 | $setup_array = array(); |
| 659 | 659 | foreach ($status_array as $item => $status) { |
| 660 | 660 | $setup_array[$item] = array( |
| 661 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 661 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
| 662 | 662 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
| 663 | 663 | 'status' => $status, |
| 664 | 664 | ); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 668 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 669 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 667 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
| 668 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
| 669 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
| 670 | 670 | foreach ($setup_array as $item => $details) { |
| 671 | 671 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
| 672 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 673 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 674 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 675 | - $content .= '</dt>' . "\n"; |
|
| 672 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
| 673 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
| 674 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
| 675 | + $content .= '</dt>'."\n"; |
|
| 676 | 676 | } |
| 677 | - $content .= '</dl>' . "\n"; |
|
| 678 | - $content .= '</div>' . "\n"; |
|
| 677 | + $content .= '</dl>'."\n"; |
|
| 678 | + $content .= '</div>'."\n"; |
|
| 679 | 679 | return $content; |
| 680 | 680 | } |
| 681 | 681 | |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | public static function layout_array_as_table($data) |
| 691 | 691 | { |
| 692 | 692 | if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
| 693 | - $data = (array)$data; |
|
| 693 | + $data = (array) $data; |
|
| 694 | 694 | } |
| 695 | 695 | ob_start(); |
| 696 | 696 | if (is_array($data)) { |
@@ -791,9 +791,9 @@ discard block |
||
| 791 | 791 | ) { |
| 792 | 792 | $page_links = array(); |
| 793 | 793 | $disable_first = $disable_last = ''; |
| 794 | - $total_items = (int)$total_items; |
|
| 795 | - $per_page = (int)$per_page; |
|
| 796 | - $current = (int)$current; |
|
| 794 | + $total_items = (int) $total_items; |
|
| 795 | + $per_page = (int) $per_page; |
|
| 796 | + $current = (int) $current; |
|
| 797 | 797 | $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
| 798 | 798 | |
| 799 | 799 | //filter items_label |
@@ -813,8 +813,8 @@ discard block |
||
| 813 | 813 | ); |
| 814 | 814 | } else { |
| 815 | 815 | $items_label = array( |
| 816 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 817 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 816 | + 'single' => '1 '.esc_html($items_label['single']), |
|
| 817 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
| 818 | 818 | ); |
| 819 | 819 | } |
| 820 | 820 | |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | |
| 827 | 827 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
| 828 | 828 | |
| 829 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 829 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
| 830 | 830 | |
| 831 | 831 | if ($current === 1) { |
| 832 | 832 | $disable_first = ' disabled'; |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
| 839 | - 'first-page' . $disable_first, |
|
| 839 | + 'first-page'.$disable_first, |
|
| 840 | 840 | esc_attr__('Go to the first page'), |
| 841 | 841 | esc_url(remove_query_arg($paged_arg_name, $url)), |
| 842 | 842 | '«' |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | |
| 845 | 845 | $page_links[] = sprintf( |
| 846 | 846 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 847 | - 'prev-page' . $disable_first, |
|
| 847 | + 'prev-page'.$disable_first, |
|
| 848 | 848 | esc_attr__('Go to the previous page'), |
| 849 | 849 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
| 850 | 850 | '‹' |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | '<span class="total-pages">%s</span>', |
| 865 | 865 | number_format_i18n($total_pages) |
| 866 | 866 | ); |
| 867 | - $page_links[] = sprintf( |
|
| 867 | + $page_links[] = sprintf( |
|
| 868 | 868 | _x('%3$s%1$s of %2$s%4$s', 'paging'), |
| 869 | 869 | $html_current_page, |
| 870 | 870 | $html_total_pages, |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | |
| 875 | 875 | $page_links[] = sprintf( |
| 876 | 876 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 877 | - 'next-page' . $disable_last, |
|
| 877 | + 'next-page'.$disable_last, |
|
| 878 | 878 | esc_attr__('Go to the next page'), |
| 879 | 879 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
| 880 | 880 | '›' |
@@ -882,13 +882,13 @@ discard block |
||
| 882 | 882 | |
| 883 | 883 | $page_links[] = sprintf( |
| 884 | 884 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 885 | - 'last-page' . $disable_last, |
|
| 885 | + 'last-page'.$disable_last, |
|
| 886 | 886 | esc_attr__('Go to the last page'), |
| 887 | 887 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
| 888 | 888 | '»' |
| 889 | 889 | ); |
| 890 | 890 | |
| 891 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 891 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
| 892 | 892 | // set page class |
| 893 | 893 | if ($total_pages) { |
| 894 | 894 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | $page_class = ' no-pages'; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 899 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | |
@@ -933,10 +933,10 @@ discard block |
||
| 933 | 933 | $query_args |
| 934 | 934 | ); |
| 935 | 935 | $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
| 936 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
| 936 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
| 937 | 937 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
| 938 | 938 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
| 939 | - return (string)apply_filters( |
|
| 939 | + return (string) apply_filters( |
|
| 940 | 940 | 'FHEE__EEH_Template__powered_by_event_espresso__html', |
| 941 | 941 | sprintf( |
| 942 | 942 | esc_html_x( |
@@ -987,6 +987,6 @@ discard block |
||
| 987 | 987 | 'add_fragment' => '', |
| 988 | 988 | ) |
| 989 | 989 | ); |
| 990 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
| 990 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : ''; |
|
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | 993 | \ No newline at end of file |
@@ -13,1354 +13,1354 @@ |
||
| 13 | 13 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Subsections |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Validatable[] |
|
| 22 | - */ |
|
| 23 | - protected $_subsections = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Strategy for laying out the form |
|
| 27 | - * |
|
| 28 | - * @var EE_Form_Section_Layout_Base |
|
| 29 | - */ |
|
| 30 | - protected $_layout_strategy; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Whether or not this form has received and validated a form submission yet |
|
| 34 | - * |
|
| 35 | - * @var boolean |
|
| 36 | - */ |
|
| 37 | - protected $_received_submission = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * message displayed to users upon successful form submission |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $_form_submission_success_message = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * message displayed to users upon unsuccessful form submission |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - protected $_form_submission_error_message = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Stores all the data that will localized for form validation |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - static protected $_js_localization = array(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * whether or not the form's localized validation JS vars have been set |
|
| 62 | - * |
|
| 63 | - * @type boolean |
|
| 64 | - */ |
|
| 65 | - static protected $_scripts_localized = false; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | - * so that they know who their parent is, and what name they've been given. |
|
| 72 | - * |
|
| 73 | - * @param array $options_array { |
|
| 74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | - * and in that order. This is handy if you want |
|
| 77 | - * the subsections to be ordered differently than the default, and if you override |
|
| 78 | - * which fields are shown |
|
| 79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | - * items from that list of inclusions) |
|
| 83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | - * @throws \EE_Error |
|
| 86 | - */ |
|
| 87 | - public function __construct($options_array = array()) |
|
| 88 | - { |
|
| 89 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | - $this); |
|
| 91 | - //call parent first, as it may be setting the name |
|
| 92 | - parent::__construct($options_array); |
|
| 93 | - //if they've included subsections in the constructor, add them now |
|
| 94 | - if (isset($options_array['include'])) { |
|
| 95 | - //we are going to make sure we ONLY have those subsections to include |
|
| 96 | - //AND we are going to make sure they're in that specified order |
|
| 97 | - $reordered_subsections = array(); |
|
| 98 | - foreach ($options_array['include'] as $input_name) { |
|
| 99 | - if (isset($this->_subsections[$input_name])) { |
|
| 100 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $this->_subsections = $reordered_subsections; |
|
| 104 | - } |
|
| 105 | - if (isset($options_array['exclude'])) { |
|
| 106 | - $exclude = $options_array['exclude']; |
|
| 107 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | - } |
|
| 109 | - if (isset($options_array['layout_strategy'])) { |
|
| 110 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | - } |
|
| 112 | - if ( ! $this->_layout_strategy) { |
|
| 113 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | - } |
|
| 115 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | - //ok so we are definitely going to want the forms JS, |
|
| 117 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | - if (did_action('wp_enqueue_scripts') |
|
| 119 | - || did_action('admin_enqueue_scripts') |
|
| 120 | - ) { |
|
| 121 | - //ok so they've constructed this object after when they should have. |
|
| 122 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | - } else { |
|
| 125 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | - } |
|
| 128 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | - if (isset($options_array['name'])) { |
|
| 130 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Finishes construction given the parent form section and this form section's name |
|
| 138 | - * |
|
| 139 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | - * @param string $name |
|
| 141 | - * @throws \EE_Error |
|
| 142 | - */ |
|
| 143 | - public function _construct_finalize($parent_form_section, $name) |
|
| 144 | - { |
|
| 145 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | - $this->_set_default_name_if_empty(); |
|
| 147 | - $this->_set_default_html_id_if_empty(); |
|
| 148 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | - } else { |
|
| 152 | - throw new EE_Error( |
|
| 153 | - sprintf( |
|
| 154 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | - 'event_espresso'), |
|
| 156 | - $subsection_name, |
|
| 157 | - get_class($this), |
|
| 158 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets the layout strategy for this form section |
|
| 170 | - * |
|
| 171 | - * @return EE_Form_Section_Layout_Base |
|
| 172 | - */ |
|
| 173 | - public function get_layout_strategy() |
|
| 174 | - { |
|
| 175 | - return $this->_layout_strategy; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Gets the HTML for a single input for this form section according |
|
| 182 | - * to the layout strategy |
|
| 183 | - * |
|
| 184 | - * @param EE_Form_Input_Base $input |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function get_html_for_input($input) |
|
| 188 | - { |
|
| 189 | - return $this->_layout_strategy->layout_input($input); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * was_submitted - checks if form inputs are present in request data |
|
| 196 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | - * proper form sections and form inputs) |
|
| 198 | - * |
|
| 199 | - * @param null $form_data |
|
| 200 | - * @return boolean |
|
| 201 | - */ |
|
| 202 | - public function was_submitted($form_data = null) |
|
| 203 | - { |
|
| 204 | - return $this->form_data_present_in($form_data); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | - * |
|
| 213 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | - * However, you CAN supply a different array. |
|
| 215 | - * Consider using set_defaults() instead however. |
|
| 216 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | - * the inputs will have the correct name in the request data for this function |
|
| 218 | - * to find them and populate the form with them. |
|
| 219 | - * If you have a flat form (with only input subsections), |
|
| 220 | - * you can supply a flat array where keys |
|
| 221 | - * are the form input names and values are their values) |
|
| 222 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | - * But if the data has already been validated |
|
| 225 | - * (eg you validated the data then stored it in the DB) |
|
| 226 | - * you may want to skip this step. |
|
| 227 | - */ |
|
| 228 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | - { |
|
| 230 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | - $validate); |
|
| 232 | - if ($req_data === null) { |
|
| 233 | - $req_data = array_merge($_GET, $_POST); |
|
| 234 | - } |
|
| 235 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | - $this); |
|
| 237 | - $this->_normalize($req_data); |
|
| 238 | - if ($validate) { |
|
| 239 | - $this->_validate(); |
|
| 240 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | - if ( ! $this->is_valid()) { |
|
| 242 | - $this->store_submitted_form_data_in_session(); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * caches the originally submitted input values in the session |
|
| 252 | - * so that they can be used to repopulate the form if it failed validation |
|
| 253 | - * |
|
| 254 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | - */ |
|
| 256 | - protected function store_submitted_form_data_in_session() |
|
| 257 | - { |
|
| 258 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | - array( |
|
| 260 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * retrieves the originally submitted input values in the session |
|
| 269 | - * so that they can be used to repopulate the form if it failed validation |
|
| 270 | - * |
|
| 271 | - * @return array |
|
| 272 | - */ |
|
| 273 | - protected function get_submitted_form_data_from_session() |
|
| 274 | - { |
|
| 275 | - $session = EE_Registry::instance()->SSN; |
|
| 276 | - if ($session instanceof EE_Session) { |
|
| 277 | - return $session->get_session_data( |
|
| 278 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | - ); |
|
| 280 | - } else { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * flushed the originally submitted input values from the session |
|
| 289 | - * |
|
| 290 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | - */ |
|
| 292 | - protected function flush_submitted_form_data_from_session() |
|
| 293 | - { |
|
| 294 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Populates this form and its subsections with data from the session. |
|
| 303 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | - * validation errors when displaying too) |
|
| 305 | - * Returns true if the form was populated from the session, false otherwise |
|
| 306 | - * |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function populate_from_session() |
|
| 310 | - { |
|
| 311 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | - if (empty($form_data_in_session)) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - $this->receive_form_submission($form_data_in_session); |
|
| 316 | - $this->flush_submitted_form_data_from_session(); |
|
| 317 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | - return true; |
|
| 319 | - } else { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Populates the default data for the form, given an array where keys are |
|
| 328 | - * the input names, and values are their values (preferably normalized to be their |
|
| 329 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | - * the value being an array formatted in teh same way |
|
| 332 | - * |
|
| 333 | - * @param array $default_data |
|
| 334 | - */ |
|
| 335 | - public function populate_defaults($default_data) |
|
| 336 | - { |
|
| 337 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | - if (isset($default_data[$subsection_name])) { |
|
| 339 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | - $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * returns true if subsection exists |
|
| 352 | - * |
|
| 353 | - * @param string $name |
|
| 354 | - * @return boolean |
|
| 355 | - */ |
|
| 356 | - public function subsection_exists($name) |
|
| 357 | - { |
|
| 358 | - return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets the subsection specified by its name |
|
| 365 | - * |
|
| 366 | - * @param string $name |
|
| 367 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | - * so that the inputs will be properly configured. |
|
| 369 | - * However, some client code may be ok |
|
| 370 | - * with construction finalize being called later |
|
| 371 | - * (realizing that the subsections' html names |
|
| 372 | - * might not be set yet, etc.) |
|
| 373 | - * @return EE_Form_Section_Base |
|
| 374 | - * @throws \EE_Error |
|
| 375 | - */ |
|
| 376 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | - { |
|
| 378 | - if ($require_construction_to_be_finalized) { |
|
| 379 | - $this->ensure_construct_finalized_called(); |
|
| 380 | - } |
|
| 381 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Gets all the validatable subsections of this form section |
|
| 388 | - * |
|
| 389 | - * @return EE_Form_Section_Validatable[] |
|
| 390 | - */ |
|
| 391 | - public function get_validatable_subsections() |
|
| 392 | - { |
|
| 393 | - $validatable_subsections = array(); |
|
| 394 | - foreach ($this->subsections() as $name => $obj) { |
|
| 395 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | - $validatable_subsections[$name] = $obj; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - return $validatable_subsections; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | - * throw an EE_Error. |
|
| 407 | - * |
|
| 408 | - * @param string $name |
|
| 409 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | - * leave this as TRUE so that the inputs will be properly |
|
| 411 | - * configured. However, some client code may be ok with |
|
| 412 | - * construction finalize being called later |
|
| 413 | - * (realizing that the subsections' html names might not be |
|
| 414 | - * set yet, etc.) |
|
| 415 | - * @return EE_Form_Input_Base |
|
| 416 | - * @throws EE_Error |
|
| 417 | - */ |
|
| 418 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | - { |
|
| 420 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | - if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | - throw new EE_Error( |
|
| 423 | - sprintf( |
|
| 424 | - __( |
|
| 425 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | - 'event_espresso' |
|
| 427 | - ), |
|
| 428 | - $name, |
|
| 429 | - get_class($this), |
|
| 430 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $subsection; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | - * otherwise throws an EE_Error |
|
| 442 | - * |
|
| 443 | - * @param string $name |
|
| 444 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | - * leave this as TRUE so that the inputs will be properly |
|
| 446 | - * configured. However, some client code may be ok with |
|
| 447 | - * construction finalize being called later |
|
| 448 | - * (realizing that the subsections' html names might not be |
|
| 449 | - * set yet, etc.) |
|
| 450 | - * @return EE_Form_Section_Proper |
|
| 451 | - * @throws EE_Error |
|
| 452 | - */ |
|
| 453 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | - { |
|
| 455 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | - if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | - throw new EE_Error( |
|
| 458 | - sprintf( |
|
| 459 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | - $name, |
|
| 461 | - get_class($this) |
|
| 462 | - ) |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - return $subsection; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | - * |
|
| 474 | - * @param string $name |
|
| 475 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | - * @throws \EE_Error |
|
| 477 | - */ |
|
| 478 | - public function get_input_value($name) |
|
| 479 | - { |
|
| 480 | - $input = $this->get_input($name); |
|
| 481 | - return $input->normalized_value(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | - * |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @return boolean |
|
| 491 | - */ |
|
| 492 | - public function is_valid() |
|
| 493 | - { |
|
| 494 | - if ( ! $this->has_received_submission()) { |
|
| 495 | - throw new EE_Error( |
|
| 496 | - sprintf( |
|
| 497 | - __( |
|
| 498 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | - "event_espresso" |
|
| 500 | - ) |
|
| 501 | - ) |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - if ( ! parent::is_valid()) { |
|
| 505 | - return false; |
|
| 506 | - } |
|
| 507 | - // ok so no general errors to this entire form section. |
|
| 508 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | - if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | - if ($set_submission_errors) { |
|
| 513 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | - } |
|
| 515 | - return false; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - return true; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * gets teh default name of this form section if none is specified |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - */ |
|
| 528 | - protected function _set_default_name_if_empty() |
|
| 529 | - { |
|
| 530 | - if ( ! $this->_name) { |
|
| 531 | - $classname = get_class($this); |
|
| 532 | - $default_name = str_replace("EE_", "", $classname); |
|
| 533 | - $this->_name = $default_name; |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 541 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 542 | - * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
| 543 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 544 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 545 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 546 | - * any CSS. |
|
| 547 | - * |
|
| 548 | - * @throws \EE_Error |
|
| 549 | - */ |
|
| 550 | - public function get_html_and_js() |
|
| 551 | - { |
|
| 552 | - $this->enqueue_js(); |
|
| 553 | - return $this->get_html(); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 560 | - * |
|
| 561 | - * @param bool $display_previously_submitted_data |
|
| 562 | - * @return string |
|
| 563 | - */ |
|
| 564 | - public function get_html($display_previously_submitted_data = true) |
|
| 565 | - { |
|
| 566 | - $this->ensure_construct_finalized_called(); |
|
| 567 | - if ($display_previously_submitted_data) { |
|
| 568 | - $this->populate_from_session(); |
|
| 569 | - } |
|
| 570 | - return $this->_layout_strategy->layout_form(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * enqueues JS and CSS for the form. |
|
| 577 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 578 | - * scripts and styles can be put in the header, but if called later |
|
| 579 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 580 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 581 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 582 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 583 | - * |
|
| 584 | - * @return string |
|
| 585 | - * @throws \EE_Error |
|
| 586 | - */ |
|
| 587 | - public function enqueue_js() |
|
| 588 | - { |
|
| 589 | - $this->_enqueue_and_localize_form_js(); |
|
| 590 | - foreach ($this->subsections() as $subsection) { |
|
| 591 | - $subsection->enqueue_js(); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 599 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 600 | - * the wp_enqueue_scripts hook. |
|
| 601 | - * However, registering the form js and localizing it can happen when we |
|
| 602 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 603 | - * could change until it's actually outputted) |
|
| 604 | - * |
|
| 605 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 606 | - * to be triggered automatically or not |
|
| 607 | - * @return void |
|
| 608 | - */ |
|
| 609 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 610 | - { |
|
| 611 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 612 | - wp_register_script( |
|
| 613 | - 'ee_form_section_validation', |
|
| 614 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 615 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 616 | - EVENT_ESPRESSO_VERSION, |
|
| 617 | - true |
|
| 618 | - ); |
|
| 619 | - wp_localize_script( |
|
| 620 | - 'ee_form_section_validation', |
|
| 621 | - 'ee_form_section_validation_init', |
|
| 622 | - array('init' => $init_form_validation_automatically ? true : false) |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * gets the variables used by form_section_validation.js. |
|
| 630 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 631 | - * but before the wordpress hook wp_loaded |
|
| 632 | - * |
|
| 633 | - * @throws \EE_Error |
|
| 634 | - */ |
|
| 635 | - public function _enqueue_and_localize_form_js() |
|
| 636 | - { |
|
| 637 | - $this->ensure_construct_finalized_called(); |
|
| 638 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 639 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 640 | - //and localize it just before the footer |
|
| 641 | - $this->localize_validation_rules(); |
|
| 642 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 643 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * add our form section data to a static variable accessible by all form sections |
|
| 650 | - * |
|
| 651 | - * @param bool $return_for_subsection |
|
| 652 | - * @return void |
|
| 653 | - * @throws \EE_Error |
|
| 654 | - */ |
|
| 655 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 656 | - { |
|
| 657 | - // we only want to localize vars ONCE for the entire form, |
|
| 658 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 659 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 660 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 661 | - 'form_section_id' => $this->html_id(true), |
|
| 662 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 663 | - 'other_data' => $this->get_other_js_data(), |
|
| 664 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 665 | - ); |
|
| 666 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 674 | - * This is primarily data added by inputs and forms in addition to any |
|
| 675 | - * scripts they might enqueue |
|
| 676 | - * |
|
| 677 | - * @param array $form_other_js_data |
|
| 678 | - * @return array |
|
| 679 | - */ |
|
| 680 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 681 | - { |
|
| 682 | - foreach ($this->subsections() as $subsection) { |
|
| 683 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 684 | - } |
|
| 685 | - return $form_other_js_data; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 692 | - * Keys are their form names, and values are the inputs themselves |
|
| 693 | - * |
|
| 694 | - * @return EE_Form_Input_Base |
|
| 695 | - */ |
|
| 696 | - public function inputs_in_subsections() |
|
| 697 | - { |
|
| 698 | - $inputs = array(); |
|
| 699 | - foreach ($this->subsections() as $subsection) { |
|
| 700 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 701 | - $inputs[$subsection->html_name()] = $subsection; |
|
| 702 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 703 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - return $inputs; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Gets a flat array of all the validation errors. |
|
| 713 | - * Keys are html names (because those should be unique) |
|
| 714 | - * and values are a string of all their validation errors |
|
| 715 | - * |
|
| 716 | - * @return string[] |
|
| 717 | - */ |
|
| 718 | - public function subsection_validation_errors_by_html_name() |
|
| 719 | - { |
|
| 720 | - $inputs = $this->inputs(); |
|
| 721 | - $errors = array(); |
|
| 722 | - foreach ($inputs as $form_input) { |
|
| 723 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 724 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - return $errors; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 734 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 735 | - */ |
|
| 736 | - public static function localize_script_for_all_forms() |
|
| 737 | - { |
|
| 738 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 739 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 740 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 741 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 742 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 743 | - : 'wp_default'; |
|
| 744 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 745 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 746 | - wp_localize_script( |
|
| 747 | - 'ee_form_section_validation', |
|
| 748 | - 'ee_form_section_vars', |
|
| 749 | - EE_Form_Section_Proper::$_js_localization |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * ensure_scripts_localized |
|
| 757 | - */ |
|
| 758 | - public function ensure_scripts_localized() |
|
| 759 | - { |
|
| 760 | - if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 761 | - $this->_enqueue_and_localize_form_js(); |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 769 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 770 | - * |
|
| 771 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 772 | - */ |
|
| 773 | - private static function _get_localized_error_messages() |
|
| 774 | - { |
|
| 775 | - return array( |
|
| 776 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 777 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
| 778 | - ); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * @return array |
|
| 785 | - */ |
|
| 786 | - public static function js_localization() |
|
| 787 | - { |
|
| 788 | - return self::$_js_localization; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * @return array |
|
| 795 | - */ |
|
| 796 | - public static function reset_js_localization() |
|
| 797 | - { |
|
| 798 | - self::$_js_localization = array(); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 805 | - * See parent function for more... |
|
| 806 | - * |
|
| 807 | - * @return array |
|
| 808 | - */ |
|
| 809 | - public function get_jquery_validation_rules() |
|
| 810 | - { |
|
| 811 | - $jquery_validation_rules = array(); |
|
| 812 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 813 | - $jquery_validation_rules = array_merge( |
|
| 814 | - $jquery_validation_rules, |
|
| 815 | - $subsection->get_jquery_validation_rules() |
|
| 816 | - ); |
|
| 817 | - } |
|
| 818 | - return $jquery_validation_rules; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 825 | - * |
|
| 826 | - * @param array $req_data like $_POST |
|
| 827 | - * @return void |
|
| 828 | - */ |
|
| 829 | - protected function _normalize($req_data) |
|
| 830 | - { |
|
| 831 | - $this->_received_submission = true; |
|
| 832 | - $this->_validation_errors = array(); |
|
| 833 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 834 | - try { |
|
| 835 | - $subsection->_normalize($req_data); |
|
| 836 | - } catch (EE_Validation_Error $e) { |
|
| 837 | - $subsection->add_validation_error($e); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * Performs validation on this form section and its subsections. |
|
| 846 | - * For each subsection, |
|
| 847 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 848 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 849 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 850 | - * you would be best to override this _validate method, |
|
| 851 | - * calling parent::_validate() first. |
|
| 852 | - */ |
|
| 853 | - protected function _validate() |
|
| 854 | - { |
|
| 855 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 856 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 857 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 858 | - } |
|
| 859 | - $subsection->_validate(); |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Gets all the validated inputs for the form section |
|
| 867 | - * |
|
| 868 | - * @return array |
|
| 869 | - */ |
|
| 870 | - public function valid_data() |
|
| 871 | - { |
|
| 872 | - $inputs = array(); |
|
| 873 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 874 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 875 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 876 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 877 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - return $inputs; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * Gets all the inputs on this form section |
|
| 887 | - * |
|
| 888 | - * @return EE_Form_Input_Base[] |
|
| 889 | - */ |
|
| 890 | - public function inputs() |
|
| 891 | - { |
|
| 892 | - $inputs = array(); |
|
| 893 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 894 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 895 | - $inputs[$subsection_name] = $subsection; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - return $inputs; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Gets all the subsections which are a proper form |
|
| 905 | - * |
|
| 906 | - * @return EE_Form_Section_Proper[] |
|
| 907 | - */ |
|
| 908 | - public function subforms() |
|
| 909 | - { |
|
| 910 | - $form_sections = array(); |
|
| 911 | - foreach ($this->subsections() as $name => $obj) { |
|
| 912 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 913 | - $form_sections[$name] = $obj; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - return $form_sections; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 923 | - * Consider using inputs() or subforms() |
|
| 924 | - * if you only want form inputs or proper form sections. |
|
| 925 | - * |
|
| 926 | - * @return EE_Form_Section_Proper[] |
|
| 927 | - */ |
|
| 928 | - public function subsections() |
|
| 929 | - { |
|
| 930 | - $this->ensure_construct_finalized_called(); |
|
| 931 | - return $this->_subsections; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 938 | - * values. (Similar to calling get_input_value on inputs) |
|
| 939 | - * |
|
| 940 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 941 | - * or just this forms' direct children inputs |
|
| 942 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 943 | - * or allow multidimensional array |
|
| 944 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 945 | - * with array keys being input names |
|
| 946 | - * (regardless of whether they are from a subsection or not), |
|
| 947 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 948 | - * where keys are always subsection names and values are either |
|
| 949 | - * the input's normalized value, or an array like the top-level array |
|
| 950 | - */ |
|
| 951 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 952 | - { |
|
| 953 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - /** |
|
| 959 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 960 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 961 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 962 | - * where keys are the input names, and values are their display values |
|
| 963 | - * |
|
| 964 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 965 | - * or just this forms' direct children inputs |
|
| 966 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 967 | - * or allow multidimensional array |
|
| 968 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 969 | - * with array keys being input names |
|
| 970 | - * (regardless of whether they are from a subsection or not), |
|
| 971 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 972 | - * where keys are always subsection names and values are either |
|
| 973 | - * the input's normalized value, or an array like the top-level array |
|
| 974 | - */ |
|
| 975 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 976 | - { |
|
| 977 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * Gets the input values from the form |
|
| 984 | - * |
|
| 985 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 986 | - * or just the normalized value |
|
| 987 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 988 | - * or just this forms' direct children inputs |
|
| 989 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 990 | - * or allow multidimensional array |
|
| 991 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 992 | - * input names (regardless of whether they are from a subsection or not), |
|
| 993 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 994 | - * where keys are always subsection names and values are either |
|
| 995 | - * the input's normalized value, or an array like the top-level array |
|
| 996 | - */ |
|
| 997 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 998 | - { |
|
| 999 | - $input_values = array(); |
|
| 1000 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1001 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1002 | - $input_values[$subsection_name] = $pretty |
|
| 1003 | - ? $subsection->pretty_value() |
|
| 1004 | - : $subsection->normalized_value(); |
|
| 1005 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1006 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1007 | - if ($flatten) { |
|
| 1008 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1009 | - } else { |
|
| 1010 | - $input_values[$subsection_name] = $subform_input_values; |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1014 | - return $input_values; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * Gets the originally submitted input values from the form |
|
| 1021 | - * |
|
| 1022 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1023 | - * or just this forms' direct children inputs |
|
| 1024 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1025 | - * with array keys being input names |
|
| 1026 | - * (regardless of whether they are from a subsection or not), |
|
| 1027 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1028 | - * where keys are always subsection names and values are either |
|
| 1029 | - * the input's normalized value, or an array like the top-level array |
|
| 1030 | - */ |
|
| 1031 | - public function submitted_values($include_subforms = false) |
|
| 1032 | - { |
|
| 1033 | - $submitted_values = array(); |
|
| 1034 | - foreach ($this->subsections() as $subsection) { |
|
| 1035 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1036 | - // is this input part of an array of inputs? |
|
| 1037 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1038 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1039 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1040 | - $subsection->raw_value() |
|
| 1041 | - ); |
|
| 1042 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1043 | - } else { |
|
| 1044 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1045 | - } |
|
| 1046 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1047 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1048 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - return $submitted_values; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Indicates whether or not this form has received a submission yet |
|
| 1058 | - * (ie, had receive_form_submission called on it yet) |
|
| 1059 | - * |
|
| 1060 | - * @return boolean |
|
| 1061 | - * @throws \EE_Error |
|
| 1062 | - */ |
|
| 1063 | - public function has_received_submission() |
|
| 1064 | - { |
|
| 1065 | - $this->ensure_construct_finalized_called(); |
|
| 1066 | - return $this->_received_submission; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - |
|
| 1070 | - |
|
| 1071 | - /** |
|
| 1072 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1073 | - * Removes the listed inputs from the form |
|
| 1074 | - * |
|
| 1075 | - * @param array $inputs_to_exclude values are the input names |
|
| 1076 | - * @return void |
|
| 1077 | - */ |
|
| 1078 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1079 | - { |
|
| 1080 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1081 | - unset($this->_subsections[$input_to_exclude_name]); |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @param array $inputs_to_hide |
|
| 1089 | - * @throws \EE_Error |
|
| 1090 | - */ |
|
| 1091 | - public function hide(array $inputs_to_hide = array()) |
|
| 1092 | - { |
|
| 1093 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1094 | - $input = $this->get_input($input_to_hide); |
|
| 1095 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1096 | - } |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * add_subsections |
|
| 1103 | - * Adds the listed subsections to the form section. |
|
| 1104 | - * If $subsection_name_to_target is provided, |
|
| 1105 | - * then new subsections are added before or after that subsection, |
|
| 1106 | - * otherwise to the start or end of the entire subsections array. |
|
| 1107 | - * |
|
| 1108 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1109 | - * where keys are their names |
|
| 1110 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1111 | - * should be added before or after |
|
| 1112 | - * IF $subsection_name_to_target is null, |
|
| 1113 | - * then $new_subsections will be added to |
|
| 1114 | - * the beginning or end of the entire subsections array |
|
| 1115 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1116 | - * $subsection_name_to_target, |
|
| 1117 | - * or if $subsection_name_to_target is null, |
|
| 1118 | - * before or after entire subsections array |
|
| 1119 | - * @return void |
|
| 1120 | - * @throws \EE_Error |
|
| 1121 | - */ |
|
| 1122 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1123 | - { |
|
| 1124 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1125 | - if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1126 | - EE_Error::add_error( |
|
| 1127 | - sprintf( |
|
| 1128 | - __( |
|
| 1129 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1130 | - "event_espresso" |
|
| 1131 | - ), |
|
| 1132 | - get_class($subsection), |
|
| 1133 | - $subsection_name, |
|
| 1134 | - $this->name() |
|
| 1135 | - ) |
|
| 1136 | - ); |
|
| 1137 | - unset($new_subsections[$subsection_name]); |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1141 | - $this->_subsections, |
|
| 1142 | - $new_subsections, |
|
| 1143 | - $subsection_name_to_target, |
|
| 1144 | - $add_before |
|
| 1145 | - ); |
|
| 1146 | - if ($this->_construction_finalized) { |
|
| 1147 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1148 | - $subsection->_construct_finalize($this, $name); |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1157 | - */ |
|
| 1158 | - public function clean_sensitive_data() |
|
| 1159 | - { |
|
| 1160 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1161 | - $subsection->clean_sensitive_data(); |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - |
|
| 1167 | - /** |
|
| 1168 | - * @param string $form_submission_error_message |
|
| 1169 | - */ |
|
| 1170 | - public function set_submission_error_message($form_submission_error_message = '') |
|
| 1171 | - { |
|
| 1172 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1173 | - ? $form_submission_error_message |
|
| 1174 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - |
|
| 1178 | - |
|
| 1179 | - /** |
|
| 1180 | - * @return string |
|
| 1181 | - */ |
|
| 1182 | - public function submission_error_message() |
|
| 1183 | - { |
|
| 1184 | - return $this->_form_submission_error_message; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * @param string $form_submission_success_message |
|
| 1191 | - */ |
|
| 1192 | - public function set_submission_success_message($form_submission_success_message) |
|
| 1193 | - { |
|
| 1194 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1195 | - ? $form_submission_success_message |
|
| 1196 | - : __('Form submitted successfully', 'event_espresso'); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * @return string |
|
| 1203 | - */ |
|
| 1204 | - public function submission_success_message() |
|
| 1205 | - { |
|
| 1206 | - return $this->_form_submission_success_message; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - |
|
| 1211 | - /** |
|
| 1212 | - * Returns the prefix that should be used on child of this form section for |
|
| 1213 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1214 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1215 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1216 | - * |
|
| 1217 | - * @return string |
|
| 1218 | - * @throws \EE_Error |
|
| 1219 | - */ |
|
| 1220 | - public function html_name_prefix() |
|
| 1221 | - { |
|
| 1222 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1223 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1224 | - } else { |
|
| 1225 | - return $this->name(); |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - |
|
| 1231 | - /** |
|
| 1232 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1233 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1234 | - * was set, which is probably nothing, or the classname) |
|
| 1235 | - * |
|
| 1236 | - * @return string |
|
| 1237 | - * @throws \EE_Error |
|
| 1238 | - */ |
|
| 1239 | - public function name() |
|
| 1240 | - { |
|
| 1241 | - $this->ensure_construct_finalized_called(); |
|
| 1242 | - return parent::name(); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * @return EE_Form_Section_Proper |
|
| 1249 | - * @throws \EE_Error |
|
| 1250 | - */ |
|
| 1251 | - public function parent_section() |
|
| 1252 | - { |
|
| 1253 | - $this->ensure_construct_finalized_called(); |
|
| 1254 | - return parent::parent_section(); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - |
|
| 1259 | - /** |
|
| 1260 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1261 | - * |
|
| 1262 | - * @return void |
|
| 1263 | - * @throws \EE_Error |
|
| 1264 | - */ |
|
| 1265 | - public function ensure_construct_finalized_called() |
|
| 1266 | - { |
|
| 1267 | - if ( ! $this->_construction_finalized) { |
|
| 1268 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - |
|
| 1274 | - /** |
|
| 1275 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1276 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1277 | - * |
|
| 1278 | - * @param array $req_data |
|
| 1279 | - * @return boolean |
|
| 1280 | - */ |
|
| 1281 | - public function form_data_present_in($req_data = null) |
|
| 1282 | - { |
|
| 1283 | - if ($req_data === null) { |
|
| 1284 | - $req_data = $_POST; |
|
| 1285 | - } |
|
| 1286 | - foreach ($this->subsections() as $subsection) { |
|
| 1287 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1288 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1289 | - return true; |
|
| 1290 | - } |
|
| 1291 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1292 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1293 | - return true; |
|
| 1294 | - } |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - return false; |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Gets validation errors for this form section and subsections |
|
| 1304 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1305 | - * gets the validation errors for ALL subsection |
|
| 1306 | - * |
|
| 1307 | - * @return EE_Validation_Error[] |
|
| 1308 | - */ |
|
| 1309 | - public function get_validation_errors_accumulated() |
|
| 1310 | - { |
|
| 1311 | - $validation_errors = $this->get_validation_errors(); |
|
| 1312 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1313 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1314 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1315 | - } else { |
|
| 1316 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1317 | - } |
|
| 1318 | - if ($validation_errors_on_this_subsection) { |
|
| 1319 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1320 | - } |
|
| 1321 | - } |
|
| 1322 | - return $validation_errors; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1329 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1330 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1331 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1332 | - * which will be returned. |
|
| 1333 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1334 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1335 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1336 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1337 | - * Etc |
|
| 1338 | - * |
|
| 1339 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1340 | - * @return EE_Form_Section_Base |
|
| 1341 | - */ |
|
| 1342 | - public function find_section_from_path($form_section_path) |
|
| 1343 | - { |
|
| 1344 | - //check if we can find the input from purely going straight up the tree |
|
| 1345 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1346 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1347 | - return $input; |
|
| 1348 | - } |
|
| 1349 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1350 | - if ($next_slash_pos !== false) { |
|
| 1351 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1352 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1353 | - } else { |
|
| 1354 | - $child_section_name = $form_section_path; |
|
| 1355 | - $subpath = ''; |
|
| 1356 | - } |
|
| 1357 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1358 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1359 | - return $child_section->find_section_from_path($subpath); |
|
| 1360 | - } else { |
|
| 1361 | - return null; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 16 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Subsections |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Validatable[] |
|
| 22 | + */ |
|
| 23 | + protected $_subsections = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Strategy for laying out the form |
|
| 27 | + * |
|
| 28 | + * @var EE_Form_Section_Layout_Base |
|
| 29 | + */ |
|
| 30 | + protected $_layout_strategy; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Whether or not this form has received and validated a form submission yet |
|
| 34 | + * |
|
| 35 | + * @var boolean |
|
| 36 | + */ |
|
| 37 | + protected $_received_submission = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * message displayed to users upon successful form submission |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $_form_submission_success_message = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * message displayed to users upon unsuccessful form submission |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + protected $_form_submission_error_message = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Stores all the data that will localized for form validation |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + static protected $_js_localization = array(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * whether or not the form's localized validation JS vars have been set |
|
| 62 | + * |
|
| 63 | + * @type boolean |
|
| 64 | + */ |
|
| 65 | + static protected $_scripts_localized = false; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | + * so that they know who their parent is, and what name they've been given. |
|
| 72 | + * |
|
| 73 | + * @param array $options_array { |
|
| 74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | + * and in that order. This is handy if you want |
|
| 77 | + * the subsections to be ordered differently than the default, and if you override |
|
| 78 | + * which fields are shown |
|
| 79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | + * items from that list of inclusions) |
|
| 83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | + * @throws \EE_Error |
|
| 86 | + */ |
|
| 87 | + public function __construct($options_array = array()) |
|
| 88 | + { |
|
| 89 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | + $this); |
|
| 91 | + //call parent first, as it may be setting the name |
|
| 92 | + parent::__construct($options_array); |
|
| 93 | + //if they've included subsections in the constructor, add them now |
|
| 94 | + if (isset($options_array['include'])) { |
|
| 95 | + //we are going to make sure we ONLY have those subsections to include |
|
| 96 | + //AND we are going to make sure they're in that specified order |
|
| 97 | + $reordered_subsections = array(); |
|
| 98 | + foreach ($options_array['include'] as $input_name) { |
|
| 99 | + if (isset($this->_subsections[$input_name])) { |
|
| 100 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $this->_subsections = $reordered_subsections; |
|
| 104 | + } |
|
| 105 | + if (isset($options_array['exclude'])) { |
|
| 106 | + $exclude = $options_array['exclude']; |
|
| 107 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | + } |
|
| 109 | + if (isset($options_array['layout_strategy'])) { |
|
| 110 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | + } |
|
| 112 | + if ( ! $this->_layout_strategy) { |
|
| 113 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | + } |
|
| 115 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | + //ok so we are definitely going to want the forms JS, |
|
| 117 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | + if (did_action('wp_enqueue_scripts') |
|
| 119 | + || did_action('admin_enqueue_scripts') |
|
| 120 | + ) { |
|
| 121 | + //ok so they've constructed this object after when they should have. |
|
| 122 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | + } else { |
|
| 125 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | + } |
|
| 128 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | + if (isset($options_array['name'])) { |
|
| 130 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Finishes construction given the parent form section and this form section's name |
|
| 138 | + * |
|
| 139 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | + * @param string $name |
|
| 141 | + * @throws \EE_Error |
|
| 142 | + */ |
|
| 143 | + public function _construct_finalize($parent_form_section, $name) |
|
| 144 | + { |
|
| 145 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | + $this->_set_default_name_if_empty(); |
|
| 147 | + $this->_set_default_html_id_if_empty(); |
|
| 148 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | + } else { |
|
| 152 | + throw new EE_Error( |
|
| 153 | + sprintf( |
|
| 154 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | + 'event_espresso'), |
|
| 156 | + $subsection_name, |
|
| 157 | + get_class($this), |
|
| 158 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets the layout strategy for this form section |
|
| 170 | + * |
|
| 171 | + * @return EE_Form_Section_Layout_Base |
|
| 172 | + */ |
|
| 173 | + public function get_layout_strategy() |
|
| 174 | + { |
|
| 175 | + return $this->_layout_strategy; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Gets the HTML for a single input for this form section according |
|
| 182 | + * to the layout strategy |
|
| 183 | + * |
|
| 184 | + * @param EE_Form_Input_Base $input |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function get_html_for_input($input) |
|
| 188 | + { |
|
| 189 | + return $this->_layout_strategy->layout_input($input); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * was_submitted - checks if form inputs are present in request data |
|
| 196 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | + * proper form sections and form inputs) |
|
| 198 | + * |
|
| 199 | + * @param null $form_data |
|
| 200 | + * @return boolean |
|
| 201 | + */ |
|
| 202 | + public function was_submitted($form_data = null) |
|
| 203 | + { |
|
| 204 | + return $this->form_data_present_in($form_data); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | + * |
|
| 213 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | + * However, you CAN supply a different array. |
|
| 215 | + * Consider using set_defaults() instead however. |
|
| 216 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | + * the inputs will have the correct name in the request data for this function |
|
| 218 | + * to find them and populate the form with them. |
|
| 219 | + * If you have a flat form (with only input subsections), |
|
| 220 | + * you can supply a flat array where keys |
|
| 221 | + * are the form input names and values are their values) |
|
| 222 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | + * But if the data has already been validated |
|
| 225 | + * (eg you validated the data then stored it in the DB) |
|
| 226 | + * you may want to skip this step. |
|
| 227 | + */ |
|
| 228 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | + { |
|
| 230 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | + $validate); |
|
| 232 | + if ($req_data === null) { |
|
| 233 | + $req_data = array_merge($_GET, $_POST); |
|
| 234 | + } |
|
| 235 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | + $this); |
|
| 237 | + $this->_normalize($req_data); |
|
| 238 | + if ($validate) { |
|
| 239 | + $this->_validate(); |
|
| 240 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | + if ( ! $this->is_valid()) { |
|
| 242 | + $this->store_submitted_form_data_in_session(); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * caches the originally submitted input values in the session |
|
| 252 | + * so that they can be used to repopulate the form if it failed validation |
|
| 253 | + * |
|
| 254 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | + */ |
|
| 256 | + protected function store_submitted_form_data_in_session() |
|
| 257 | + { |
|
| 258 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | + array( |
|
| 260 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * retrieves the originally submitted input values in the session |
|
| 269 | + * so that they can be used to repopulate the form if it failed validation |
|
| 270 | + * |
|
| 271 | + * @return array |
|
| 272 | + */ |
|
| 273 | + protected function get_submitted_form_data_from_session() |
|
| 274 | + { |
|
| 275 | + $session = EE_Registry::instance()->SSN; |
|
| 276 | + if ($session instanceof EE_Session) { |
|
| 277 | + return $session->get_session_data( |
|
| 278 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | + ); |
|
| 280 | + } else { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * flushed the originally submitted input values from the session |
|
| 289 | + * |
|
| 290 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | + */ |
|
| 292 | + protected function flush_submitted_form_data_from_session() |
|
| 293 | + { |
|
| 294 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Populates this form and its subsections with data from the session. |
|
| 303 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | + * validation errors when displaying too) |
|
| 305 | + * Returns true if the form was populated from the session, false otherwise |
|
| 306 | + * |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function populate_from_session() |
|
| 310 | + { |
|
| 311 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | + if (empty($form_data_in_session)) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + $this->receive_form_submission($form_data_in_session); |
|
| 316 | + $this->flush_submitted_form_data_from_session(); |
|
| 317 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | + return true; |
|
| 319 | + } else { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Populates the default data for the form, given an array where keys are |
|
| 328 | + * the input names, and values are their values (preferably normalized to be their |
|
| 329 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | + * the value being an array formatted in teh same way |
|
| 332 | + * |
|
| 333 | + * @param array $default_data |
|
| 334 | + */ |
|
| 335 | + public function populate_defaults($default_data) |
|
| 336 | + { |
|
| 337 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | + if (isset($default_data[$subsection_name])) { |
|
| 339 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * returns true if subsection exists |
|
| 352 | + * |
|
| 353 | + * @param string $name |
|
| 354 | + * @return boolean |
|
| 355 | + */ |
|
| 356 | + public function subsection_exists($name) |
|
| 357 | + { |
|
| 358 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets the subsection specified by its name |
|
| 365 | + * |
|
| 366 | + * @param string $name |
|
| 367 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | + * so that the inputs will be properly configured. |
|
| 369 | + * However, some client code may be ok |
|
| 370 | + * with construction finalize being called later |
|
| 371 | + * (realizing that the subsections' html names |
|
| 372 | + * might not be set yet, etc.) |
|
| 373 | + * @return EE_Form_Section_Base |
|
| 374 | + * @throws \EE_Error |
|
| 375 | + */ |
|
| 376 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | + { |
|
| 378 | + if ($require_construction_to_be_finalized) { |
|
| 379 | + $this->ensure_construct_finalized_called(); |
|
| 380 | + } |
|
| 381 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Gets all the validatable subsections of this form section |
|
| 388 | + * |
|
| 389 | + * @return EE_Form_Section_Validatable[] |
|
| 390 | + */ |
|
| 391 | + public function get_validatable_subsections() |
|
| 392 | + { |
|
| 393 | + $validatable_subsections = array(); |
|
| 394 | + foreach ($this->subsections() as $name => $obj) { |
|
| 395 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | + $validatable_subsections[$name] = $obj; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + return $validatable_subsections; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | + * throw an EE_Error. |
|
| 407 | + * |
|
| 408 | + * @param string $name |
|
| 409 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | + * leave this as TRUE so that the inputs will be properly |
|
| 411 | + * configured. However, some client code may be ok with |
|
| 412 | + * construction finalize being called later |
|
| 413 | + * (realizing that the subsections' html names might not be |
|
| 414 | + * set yet, etc.) |
|
| 415 | + * @return EE_Form_Input_Base |
|
| 416 | + * @throws EE_Error |
|
| 417 | + */ |
|
| 418 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | + { |
|
| 420 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | + throw new EE_Error( |
|
| 423 | + sprintf( |
|
| 424 | + __( |
|
| 425 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | + 'event_espresso' |
|
| 427 | + ), |
|
| 428 | + $name, |
|
| 429 | + get_class($this), |
|
| 430 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $subsection; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | + * otherwise throws an EE_Error |
|
| 442 | + * |
|
| 443 | + * @param string $name |
|
| 444 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | + * leave this as TRUE so that the inputs will be properly |
|
| 446 | + * configured. However, some client code may be ok with |
|
| 447 | + * construction finalize being called later |
|
| 448 | + * (realizing that the subsections' html names might not be |
|
| 449 | + * set yet, etc.) |
|
| 450 | + * @return EE_Form_Section_Proper |
|
| 451 | + * @throws EE_Error |
|
| 452 | + */ |
|
| 453 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | + { |
|
| 455 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | + throw new EE_Error( |
|
| 458 | + sprintf( |
|
| 459 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | + $name, |
|
| 461 | + get_class($this) |
|
| 462 | + ) |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + return $subsection; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | + * |
|
| 474 | + * @param string $name |
|
| 475 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | + * @throws \EE_Error |
|
| 477 | + */ |
|
| 478 | + public function get_input_value($name) |
|
| 479 | + { |
|
| 480 | + $input = $this->get_input($name); |
|
| 481 | + return $input->normalized_value(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | + * |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @return boolean |
|
| 491 | + */ |
|
| 492 | + public function is_valid() |
|
| 493 | + { |
|
| 494 | + if ( ! $this->has_received_submission()) { |
|
| 495 | + throw new EE_Error( |
|
| 496 | + sprintf( |
|
| 497 | + __( |
|
| 498 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | + "event_espresso" |
|
| 500 | + ) |
|
| 501 | + ) |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + if ( ! parent::is_valid()) { |
|
| 505 | + return false; |
|
| 506 | + } |
|
| 507 | + // ok so no general errors to this entire form section. |
|
| 508 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | + if ($set_submission_errors) { |
|
| 513 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | + } |
|
| 515 | + return false; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + return true; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * gets teh default name of this form section if none is specified |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + */ |
|
| 528 | + protected function _set_default_name_if_empty() |
|
| 529 | + { |
|
| 530 | + if ( ! $this->_name) { |
|
| 531 | + $classname = get_class($this); |
|
| 532 | + $default_name = str_replace("EE_", "", $classname); |
|
| 533 | + $this->_name = $default_name; |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 541 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 542 | + * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
| 543 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 544 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 545 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 546 | + * any CSS. |
|
| 547 | + * |
|
| 548 | + * @throws \EE_Error |
|
| 549 | + */ |
|
| 550 | + public function get_html_and_js() |
|
| 551 | + { |
|
| 552 | + $this->enqueue_js(); |
|
| 553 | + return $this->get_html(); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 560 | + * |
|
| 561 | + * @param bool $display_previously_submitted_data |
|
| 562 | + * @return string |
|
| 563 | + */ |
|
| 564 | + public function get_html($display_previously_submitted_data = true) |
|
| 565 | + { |
|
| 566 | + $this->ensure_construct_finalized_called(); |
|
| 567 | + if ($display_previously_submitted_data) { |
|
| 568 | + $this->populate_from_session(); |
|
| 569 | + } |
|
| 570 | + return $this->_layout_strategy->layout_form(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * enqueues JS and CSS for the form. |
|
| 577 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 578 | + * scripts and styles can be put in the header, but if called later |
|
| 579 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 580 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 581 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 582 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 583 | + * |
|
| 584 | + * @return string |
|
| 585 | + * @throws \EE_Error |
|
| 586 | + */ |
|
| 587 | + public function enqueue_js() |
|
| 588 | + { |
|
| 589 | + $this->_enqueue_and_localize_form_js(); |
|
| 590 | + foreach ($this->subsections() as $subsection) { |
|
| 591 | + $subsection->enqueue_js(); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 599 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 600 | + * the wp_enqueue_scripts hook. |
|
| 601 | + * However, registering the form js and localizing it can happen when we |
|
| 602 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 603 | + * could change until it's actually outputted) |
|
| 604 | + * |
|
| 605 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 606 | + * to be triggered automatically or not |
|
| 607 | + * @return void |
|
| 608 | + */ |
|
| 609 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 610 | + { |
|
| 611 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 612 | + wp_register_script( |
|
| 613 | + 'ee_form_section_validation', |
|
| 614 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 615 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 616 | + EVENT_ESPRESSO_VERSION, |
|
| 617 | + true |
|
| 618 | + ); |
|
| 619 | + wp_localize_script( |
|
| 620 | + 'ee_form_section_validation', |
|
| 621 | + 'ee_form_section_validation_init', |
|
| 622 | + array('init' => $init_form_validation_automatically ? true : false) |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * gets the variables used by form_section_validation.js. |
|
| 630 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 631 | + * but before the wordpress hook wp_loaded |
|
| 632 | + * |
|
| 633 | + * @throws \EE_Error |
|
| 634 | + */ |
|
| 635 | + public function _enqueue_and_localize_form_js() |
|
| 636 | + { |
|
| 637 | + $this->ensure_construct_finalized_called(); |
|
| 638 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 639 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 640 | + //and localize it just before the footer |
|
| 641 | + $this->localize_validation_rules(); |
|
| 642 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 643 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * add our form section data to a static variable accessible by all form sections |
|
| 650 | + * |
|
| 651 | + * @param bool $return_for_subsection |
|
| 652 | + * @return void |
|
| 653 | + * @throws \EE_Error |
|
| 654 | + */ |
|
| 655 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 656 | + { |
|
| 657 | + // we only want to localize vars ONCE for the entire form, |
|
| 658 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 659 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 660 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 661 | + 'form_section_id' => $this->html_id(true), |
|
| 662 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 663 | + 'other_data' => $this->get_other_js_data(), |
|
| 664 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 665 | + ); |
|
| 666 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 674 | + * This is primarily data added by inputs and forms in addition to any |
|
| 675 | + * scripts they might enqueue |
|
| 676 | + * |
|
| 677 | + * @param array $form_other_js_data |
|
| 678 | + * @return array |
|
| 679 | + */ |
|
| 680 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 681 | + { |
|
| 682 | + foreach ($this->subsections() as $subsection) { |
|
| 683 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 684 | + } |
|
| 685 | + return $form_other_js_data; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 692 | + * Keys are their form names, and values are the inputs themselves |
|
| 693 | + * |
|
| 694 | + * @return EE_Form_Input_Base |
|
| 695 | + */ |
|
| 696 | + public function inputs_in_subsections() |
|
| 697 | + { |
|
| 698 | + $inputs = array(); |
|
| 699 | + foreach ($this->subsections() as $subsection) { |
|
| 700 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 701 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 702 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 703 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + return $inputs; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Gets a flat array of all the validation errors. |
|
| 713 | + * Keys are html names (because those should be unique) |
|
| 714 | + * and values are a string of all their validation errors |
|
| 715 | + * |
|
| 716 | + * @return string[] |
|
| 717 | + */ |
|
| 718 | + public function subsection_validation_errors_by_html_name() |
|
| 719 | + { |
|
| 720 | + $inputs = $this->inputs(); |
|
| 721 | + $errors = array(); |
|
| 722 | + foreach ($inputs as $form_input) { |
|
| 723 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 724 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + return $errors; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 734 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 735 | + */ |
|
| 736 | + public static function localize_script_for_all_forms() |
|
| 737 | + { |
|
| 738 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 739 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 740 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 741 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 742 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 743 | + : 'wp_default'; |
|
| 744 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 745 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 746 | + wp_localize_script( |
|
| 747 | + 'ee_form_section_validation', |
|
| 748 | + 'ee_form_section_vars', |
|
| 749 | + EE_Form_Section_Proper::$_js_localization |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * ensure_scripts_localized |
|
| 757 | + */ |
|
| 758 | + public function ensure_scripts_localized() |
|
| 759 | + { |
|
| 760 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 761 | + $this->_enqueue_and_localize_form_js(); |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 769 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 770 | + * |
|
| 771 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 772 | + */ |
|
| 773 | + private static function _get_localized_error_messages() |
|
| 774 | + { |
|
| 775 | + return array( |
|
| 776 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 777 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
| 778 | + ); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * @return array |
|
| 785 | + */ |
|
| 786 | + public static function js_localization() |
|
| 787 | + { |
|
| 788 | + return self::$_js_localization; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * @return array |
|
| 795 | + */ |
|
| 796 | + public static function reset_js_localization() |
|
| 797 | + { |
|
| 798 | + self::$_js_localization = array(); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 805 | + * See parent function for more... |
|
| 806 | + * |
|
| 807 | + * @return array |
|
| 808 | + */ |
|
| 809 | + public function get_jquery_validation_rules() |
|
| 810 | + { |
|
| 811 | + $jquery_validation_rules = array(); |
|
| 812 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 813 | + $jquery_validation_rules = array_merge( |
|
| 814 | + $jquery_validation_rules, |
|
| 815 | + $subsection->get_jquery_validation_rules() |
|
| 816 | + ); |
|
| 817 | + } |
|
| 818 | + return $jquery_validation_rules; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 825 | + * |
|
| 826 | + * @param array $req_data like $_POST |
|
| 827 | + * @return void |
|
| 828 | + */ |
|
| 829 | + protected function _normalize($req_data) |
|
| 830 | + { |
|
| 831 | + $this->_received_submission = true; |
|
| 832 | + $this->_validation_errors = array(); |
|
| 833 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 834 | + try { |
|
| 835 | + $subsection->_normalize($req_data); |
|
| 836 | + } catch (EE_Validation_Error $e) { |
|
| 837 | + $subsection->add_validation_error($e); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * Performs validation on this form section and its subsections. |
|
| 846 | + * For each subsection, |
|
| 847 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 848 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 849 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 850 | + * you would be best to override this _validate method, |
|
| 851 | + * calling parent::_validate() first. |
|
| 852 | + */ |
|
| 853 | + protected function _validate() |
|
| 854 | + { |
|
| 855 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 856 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 857 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 858 | + } |
|
| 859 | + $subsection->_validate(); |
|
| 860 | + } |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Gets all the validated inputs for the form section |
|
| 867 | + * |
|
| 868 | + * @return array |
|
| 869 | + */ |
|
| 870 | + public function valid_data() |
|
| 871 | + { |
|
| 872 | + $inputs = array(); |
|
| 873 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 874 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 875 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 876 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 877 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + return $inputs; |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * Gets all the inputs on this form section |
|
| 887 | + * |
|
| 888 | + * @return EE_Form_Input_Base[] |
|
| 889 | + */ |
|
| 890 | + public function inputs() |
|
| 891 | + { |
|
| 892 | + $inputs = array(); |
|
| 893 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 894 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 895 | + $inputs[$subsection_name] = $subsection; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + return $inputs; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Gets all the subsections which are a proper form |
|
| 905 | + * |
|
| 906 | + * @return EE_Form_Section_Proper[] |
|
| 907 | + */ |
|
| 908 | + public function subforms() |
|
| 909 | + { |
|
| 910 | + $form_sections = array(); |
|
| 911 | + foreach ($this->subsections() as $name => $obj) { |
|
| 912 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 913 | + $form_sections[$name] = $obj; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + return $form_sections; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 923 | + * Consider using inputs() or subforms() |
|
| 924 | + * if you only want form inputs or proper form sections. |
|
| 925 | + * |
|
| 926 | + * @return EE_Form_Section_Proper[] |
|
| 927 | + */ |
|
| 928 | + public function subsections() |
|
| 929 | + { |
|
| 930 | + $this->ensure_construct_finalized_called(); |
|
| 931 | + return $this->_subsections; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 938 | + * values. (Similar to calling get_input_value on inputs) |
|
| 939 | + * |
|
| 940 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 941 | + * or just this forms' direct children inputs |
|
| 942 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 943 | + * or allow multidimensional array |
|
| 944 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 945 | + * with array keys being input names |
|
| 946 | + * (regardless of whether they are from a subsection or not), |
|
| 947 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 948 | + * where keys are always subsection names and values are either |
|
| 949 | + * the input's normalized value, or an array like the top-level array |
|
| 950 | + */ |
|
| 951 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 952 | + { |
|
| 953 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + /** |
|
| 959 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 960 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 961 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 962 | + * where keys are the input names, and values are their display values |
|
| 963 | + * |
|
| 964 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 965 | + * or just this forms' direct children inputs |
|
| 966 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 967 | + * or allow multidimensional array |
|
| 968 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 969 | + * with array keys being input names |
|
| 970 | + * (regardless of whether they are from a subsection or not), |
|
| 971 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 972 | + * where keys are always subsection names and values are either |
|
| 973 | + * the input's normalized value, or an array like the top-level array |
|
| 974 | + */ |
|
| 975 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 976 | + { |
|
| 977 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * Gets the input values from the form |
|
| 984 | + * |
|
| 985 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 986 | + * or just the normalized value |
|
| 987 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 988 | + * or just this forms' direct children inputs |
|
| 989 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 990 | + * or allow multidimensional array |
|
| 991 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 992 | + * input names (regardless of whether they are from a subsection or not), |
|
| 993 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 994 | + * where keys are always subsection names and values are either |
|
| 995 | + * the input's normalized value, or an array like the top-level array |
|
| 996 | + */ |
|
| 997 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 998 | + { |
|
| 999 | + $input_values = array(); |
|
| 1000 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1001 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1002 | + $input_values[$subsection_name] = $pretty |
|
| 1003 | + ? $subsection->pretty_value() |
|
| 1004 | + : $subsection->normalized_value(); |
|
| 1005 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1006 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1007 | + if ($flatten) { |
|
| 1008 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1009 | + } else { |
|
| 1010 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | + return $input_values; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * Gets the originally submitted input values from the form |
|
| 1021 | + * |
|
| 1022 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1023 | + * or just this forms' direct children inputs |
|
| 1024 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1025 | + * with array keys being input names |
|
| 1026 | + * (regardless of whether they are from a subsection or not), |
|
| 1027 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1028 | + * where keys are always subsection names and values are either |
|
| 1029 | + * the input's normalized value, or an array like the top-level array |
|
| 1030 | + */ |
|
| 1031 | + public function submitted_values($include_subforms = false) |
|
| 1032 | + { |
|
| 1033 | + $submitted_values = array(); |
|
| 1034 | + foreach ($this->subsections() as $subsection) { |
|
| 1035 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1036 | + // is this input part of an array of inputs? |
|
| 1037 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1038 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1039 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1040 | + $subsection->raw_value() |
|
| 1041 | + ); |
|
| 1042 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1043 | + } else { |
|
| 1044 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1045 | + } |
|
| 1046 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1047 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1048 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + return $submitted_values; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Indicates whether or not this form has received a submission yet |
|
| 1058 | + * (ie, had receive_form_submission called on it yet) |
|
| 1059 | + * |
|
| 1060 | + * @return boolean |
|
| 1061 | + * @throws \EE_Error |
|
| 1062 | + */ |
|
| 1063 | + public function has_received_submission() |
|
| 1064 | + { |
|
| 1065 | + $this->ensure_construct_finalized_called(); |
|
| 1066 | + return $this->_received_submission; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + |
|
| 1070 | + |
|
| 1071 | + /** |
|
| 1072 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1073 | + * Removes the listed inputs from the form |
|
| 1074 | + * |
|
| 1075 | + * @param array $inputs_to_exclude values are the input names |
|
| 1076 | + * @return void |
|
| 1077 | + */ |
|
| 1078 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1079 | + { |
|
| 1080 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1081 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @param array $inputs_to_hide |
|
| 1089 | + * @throws \EE_Error |
|
| 1090 | + */ |
|
| 1091 | + public function hide(array $inputs_to_hide = array()) |
|
| 1092 | + { |
|
| 1093 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1094 | + $input = $this->get_input($input_to_hide); |
|
| 1095 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1096 | + } |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * add_subsections |
|
| 1103 | + * Adds the listed subsections to the form section. |
|
| 1104 | + * If $subsection_name_to_target is provided, |
|
| 1105 | + * then new subsections are added before or after that subsection, |
|
| 1106 | + * otherwise to the start or end of the entire subsections array. |
|
| 1107 | + * |
|
| 1108 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1109 | + * where keys are their names |
|
| 1110 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1111 | + * should be added before or after |
|
| 1112 | + * IF $subsection_name_to_target is null, |
|
| 1113 | + * then $new_subsections will be added to |
|
| 1114 | + * the beginning or end of the entire subsections array |
|
| 1115 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1116 | + * $subsection_name_to_target, |
|
| 1117 | + * or if $subsection_name_to_target is null, |
|
| 1118 | + * before or after entire subsections array |
|
| 1119 | + * @return void |
|
| 1120 | + * @throws \EE_Error |
|
| 1121 | + */ |
|
| 1122 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1123 | + { |
|
| 1124 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1125 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1126 | + EE_Error::add_error( |
|
| 1127 | + sprintf( |
|
| 1128 | + __( |
|
| 1129 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1130 | + "event_espresso" |
|
| 1131 | + ), |
|
| 1132 | + get_class($subsection), |
|
| 1133 | + $subsection_name, |
|
| 1134 | + $this->name() |
|
| 1135 | + ) |
|
| 1136 | + ); |
|
| 1137 | + unset($new_subsections[$subsection_name]); |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1141 | + $this->_subsections, |
|
| 1142 | + $new_subsections, |
|
| 1143 | + $subsection_name_to_target, |
|
| 1144 | + $add_before |
|
| 1145 | + ); |
|
| 1146 | + if ($this->_construction_finalized) { |
|
| 1147 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1148 | + $subsection->_construct_finalize($this, $name); |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1157 | + */ |
|
| 1158 | + public function clean_sensitive_data() |
|
| 1159 | + { |
|
| 1160 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1161 | + $subsection->clean_sensitive_data(); |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + |
|
| 1167 | + /** |
|
| 1168 | + * @param string $form_submission_error_message |
|
| 1169 | + */ |
|
| 1170 | + public function set_submission_error_message($form_submission_error_message = '') |
|
| 1171 | + { |
|
| 1172 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1173 | + ? $form_submission_error_message |
|
| 1174 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + |
|
| 1178 | + |
|
| 1179 | + /** |
|
| 1180 | + * @return string |
|
| 1181 | + */ |
|
| 1182 | + public function submission_error_message() |
|
| 1183 | + { |
|
| 1184 | + return $this->_form_submission_error_message; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * @param string $form_submission_success_message |
|
| 1191 | + */ |
|
| 1192 | + public function set_submission_success_message($form_submission_success_message) |
|
| 1193 | + { |
|
| 1194 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1195 | + ? $form_submission_success_message |
|
| 1196 | + : __('Form submitted successfully', 'event_espresso'); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * @return string |
|
| 1203 | + */ |
|
| 1204 | + public function submission_success_message() |
|
| 1205 | + { |
|
| 1206 | + return $this->_form_submission_success_message; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + |
|
| 1211 | + /** |
|
| 1212 | + * Returns the prefix that should be used on child of this form section for |
|
| 1213 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1214 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1215 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1216 | + * |
|
| 1217 | + * @return string |
|
| 1218 | + * @throws \EE_Error |
|
| 1219 | + */ |
|
| 1220 | + public function html_name_prefix() |
|
| 1221 | + { |
|
| 1222 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1223 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1224 | + } else { |
|
| 1225 | + return $this->name(); |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + |
|
| 1231 | + /** |
|
| 1232 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1233 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1234 | + * was set, which is probably nothing, or the classname) |
|
| 1235 | + * |
|
| 1236 | + * @return string |
|
| 1237 | + * @throws \EE_Error |
|
| 1238 | + */ |
|
| 1239 | + public function name() |
|
| 1240 | + { |
|
| 1241 | + $this->ensure_construct_finalized_called(); |
|
| 1242 | + return parent::name(); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * @return EE_Form_Section_Proper |
|
| 1249 | + * @throws \EE_Error |
|
| 1250 | + */ |
|
| 1251 | + public function parent_section() |
|
| 1252 | + { |
|
| 1253 | + $this->ensure_construct_finalized_called(); |
|
| 1254 | + return parent::parent_section(); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + |
|
| 1259 | + /** |
|
| 1260 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1261 | + * |
|
| 1262 | + * @return void |
|
| 1263 | + * @throws \EE_Error |
|
| 1264 | + */ |
|
| 1265 | + public function ensure_construct_finalized_called() |
|
| 1266 | + { |
|
| 1267 | + if ( ! $this->_construction_finalized) { |
|
| 1268 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + |
|
| 1274 | + /** |
|
| 1275 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1276 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1277 | + * |
|
| 1278 | + * @param array $req_data |
|
| 1279 | + * @return boolean |
|
| 1280 | + */ |
|
| 1281 | + public function form_data_present_in($req_data = null) |
|
| 1282 | + { |
|
| 1283 | + if ($req_data === null) { |
|
| 1284 | + $req_data = $_POST; |
|
| 1285 | + } |
|
| 1286 | + foreach ($this->subsections() as $subsection) { |
|
| 1287 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1288 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1289 | + return true; |
|
| 1290 | + } |
|
| 1291 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1292 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1293 | + return true; |
|
| 1294 | + } |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + return false; |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Gets validation errors for this form section and subsections |
|
| 1304 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1305 | + * gets the validation errors for ALL subsection |
|
| 1306 | + * |
|
| 1307 | + * @return EE_Validation_Error[] |
|
| 1308 | + */ |
|
| 1309 | + public function get_validation_errors_accumulated() |
|
| 1310 | + { |
|
| 1311 | + $validation_errors = $this->get_validation_errors(); |
|
| 1312 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1313 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1314 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1315 | + } else { |
|
| 1316 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1317 | + } |
|
| 1318 | + if ($validation_errors_on_this_subsection) { |
|
| 1319 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1320 | + } |
|
| 1321 | + } |
|
| 1322 | + return $validation_errors; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1329 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1330 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1331 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1332 | + * which will be returned. |
|
| 1333 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1334 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1335 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1336 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1337 | + * Etc |
|
| 1338 | + * |
|
| 1339 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1340 | + * @return EE_Form_Section_Base |
|
| 1341 | + */ |
|
| 1342 | + public function find_section_from_path($form_section_path) |
|
| 1343 | + { |
|
| 1344 | + //check if we can find the input from purely going straight up the tree |
|
| 1345 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1346 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1347 | + return $input; |
|
| 1348 | + } |
|
| 1349 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1350 | + if ($next_slash_pos !== false) { |
|
| 1351 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1352 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1353 | + } else { |
|
| 1354 | + $child_section_name = $form_section_path; |
|
| 1355 | + $subpath = ''; |
|
| 1356 | + } |
|
| 1357 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1358 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1359 | + return $child_section->find_section_from_path($subpath); |
|
| 1360 | + } else { |
|
| 1361 | + return null; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | 1364 | |
| 1365 | 1365 | } |
| 1366 | 1366 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\core\libraries\iframe_display; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 5 | - exit( 'No direct script access allowed' ); |
|
| 5 | + exit( 'No direct script access allowed' ); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -18,336 +18,336 @@ discard block |
||
| 18 | 18 | class Iframe |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /* |
|
| 21 | + /* |
|
| 22 | 22 | * HTML for notices and ajax gif |
| 23 | 23 | * @var string $title |
| 24 | 24 | */ |
| 25 | - protected $title = ''; |
|
| 25 | + protected $title = ''; |
|
| 26 | 26 | |
| 27 | - /* |
|
| 27 | + /* |
|
| 28 | 28 | * HTML for the content being displayed |
| 29 | 29 | * @var string $content |
| 30 | 30 | */ |
| 31 | - protected $content = ''; |
|
| 31 | + protected $content = ''; |
|
| 32 | 32 | |
| 33 | - /* |
|
| 33 | + /* |
|
| 34 | 34 | * whether or not to call wp_head() and wp_footer() |
| 35 | 35 | * @var boolean $enqueue_wp_assets |
| 36 | 36 | */ |
| 37 | - protected $enqueue_wp_assets = false; |
|
| 37 | + protected $enqueue_wp_assets = false; |
|
| 38 | 38 | |
| 39 | - /* |
|
| 39 | + /* |
|
| 40 | 40 | * an array of CSS URLs |
| 41 | 41 | * @var array $css |
| 42 | 42 | */ |
| 43 | - protected $css = array(); |
|
| 43 | + protected $css = array(); |
|
| 44 | 44 | |
| 45 | - /* |
|
| 45 | + /* |
|
| 46 | 46 | * an array of JS URLs to be set in the HTML header. |
| 47 | 47 | * @var array $header_js |
| 48 | 48 | */ |
| 49 | - protected $header_js = array(); |
|
| 49 | + protected $header_js = array(); |
|
| 50 | 50 | |
| 51 | - /* |
|
| 51 | + /* |
|
| 52 | 52 | * an array of JS URLs to be displayed before the HTML </body> tag |
| 53 | 53 | * @var array $footer_js |
| 54 | 54 | */ |
| 55 | - protected $footer_js = array(); |
|
| 55 | + protected $footer_js = array(); |
|
| 56 | 56 | |
| 57 | - /* |
|
| 57 | + /* |
|
| 58 | 58 | * an array of JSON vars to be set in the HTML header. |
| 59 | 59 | * @var array $localized_vars |
| 60 | 60 | */ |
| 61 | - protected $localized_vars = array(); |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Iframe constructor |
|
| 67 | - * |
|
| 68 | - * @param string $title |
|
| 69 | - * @param string $content |
|
| 70 | - * @throws \DomainException |
|
| 71 | - */ |
|
| 72 | - public function __construct( $title, $content ) |
|
| 73 | - { |
|
| 74 | - global $wp_version; |
|
| 75 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 76 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 77 | - } |
|
| 78 | - $this->setContent( $content ); |
|
| 79 | - $this->setTitle( $title ); |
|
| 80 | - $this->addStylesheets( |
|
| 81 | - apply_filters( |
|
| 82 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
| 83 | - array( |
|
| 84 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 85 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
| 86 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 87 | - ), |
|
| 88 | - $this |
|
| 89 | - ) |
|
| 90 | - ); |
|
| 91 | - $this->addScripts( |
|
| 92 | - apply_filters( |
|
| 93 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
| 94 | - array( |
|
| 95 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 96 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
| 97 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 98 | - ), |
|
| 99 | - $this |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - if ( |
|
| 103 | - apply_filters( |
|
| 104 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
| 105 | - false |
|
| 106 | - ) |
|
| 107 | - ) { |
|
| 108 | - $this->addStylesheets( |
|
| 109 | - apply_filters( |
|
| 110 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
| 111 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
| 112 | - $this |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param string $title |
|
| 122 | - * @throws \DomainException |
|
| 123 | - */ |
|
| 124 | - public function setTitle( $title ) |
|
| 125 | - { |
|
| 126 | - if ( empty( $title ) ) { |
|
| 127 | - throw new \DomainException( |
|
| 128 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - $this->title = $title; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param string $content |
|
| 138 | - * @throws \DomainException |
|
| 139 | - */ |
|
| 140 | - public function setContent( $content ) |
|
| 141 | - { |
|
| 142 | - if ( empty( $content ) ) { |
|
| 143 | - throw new \DomainException( |
|
| 144 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - $this->content = $content; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param boolean $enqueue_wp_assets |
|
| 154 | - */ |
|
| 155 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 156 | - { |
|
| 157 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param array $stylesheets |
|
| 164 | - * @throws \DomainException |
|
| 165 | - */ |
|
| 166 | - public function addStylesheets( array $stylesheets ) |
|
| 167 | - { |
|
| 168 | - if ( empty( $stylesheets ) ) { |
|
| 169 | - throw new \DomainException( |
|
| 170 | - esc_html__( |
|
| 171 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ) |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 177 | - $this->css[ $handle ] = $stylesheet; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @param array $scripts |
|
| 185 | - * @param bool $add_to_header |
|
| 186 | - * @throws \DomainException |
|
| 187 | - */ |
|
| 188 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
| 189 | - { |
|
| 190 | - if ( empty( $scripts ) ) { |
|
| 191 | - throw new \DomainException( |
|
| 192 | - esc_html__( |
|
| 193 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ) |
|
| 196 | - ); |
|
| 197 | - } |
|
| 198 | - foreach ( $scripts as $handle => $script ) { |
|
| 199 | - if ( $add_to_header ) { |
|
| 200 | - $this->header_js[ $handle ] = $script; |
|
| 201 | - } else { |
|
| 202 | - $this->footer_js[ $handle ] = $script; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param array $vars |
|
| 211 | - * @param string $var_name |
|
| 212 | - * @throws \DomainException |
|
| 213 | - */ |
|
| 214 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 215 | - { |
|
| 216 | - if ( empty( $vars ) ) { |
|
| 217 | - throw new \DomainException( |
|
| 218 | - esc_html__( |
|
| 219 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
| 220 | - 'event_espresso' |
|
| 221 | - ) |
|
| 222 | - ); |
|
| 223 | - } |
|
| 224 | - foreach ( $vars as $handle => $var ) { |
|
| 225 | - if ( $var_name === 'eei18n' ) { |
|
| 226 | - \EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 227 | - } else { |
|
| 228 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 229 | - $this->localized_vars[ $var_name ] = array(); |
|
| 230 | - } |
|
| 231 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param string $utm_content |
|
| 240 | - * @throws \DomainException |
|
| 241 | - */ |
|
| 242 | - public function display($utm_content = '') |
|
| 243 | - { |
|
| 244 | - $this->content .= \EEH_Template::powered_by_event_espresso( |
|
| 245 | - '', |
|
| 246 | - '', |
|
| 247 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
| 248 | - ); |
|
| 249 | - \EE_System::do_not_cache(); |
|
| 250 | - echo $this->getTemplate(); |
|
| 251 | - exit; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @return string |
|
| 258 | - * @throws \DomainException |
|
| 259 | - */ |
|
| 260 | - public function getTemplate() |
|
| 261 | - { |
|
| 262 | - return \EEH_Template::display_template( |
|
| 263 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 264 | - array( |
|
| 265 | - 'title' => apply_filters( |
|
| 266 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
| 267 | - $this->title, |
|
| 268 | - $this |
|
| 269 | - ), |
|
| 270 | - 'content' => apply_filters( |
|
| 271 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
| 272 | - $this->content, |
|
| 273 | - $this |
|
| 274 | - ), |
|
| 275 | - 'enqueue_wp_assets' => apply_filters( |
|
| 276 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
| 277 | - $this->enqueue_wp_assets, |
|
| 278 | - $this |
|
| 279 | - ), |
|
| 280 | - 'css' => (array)apply_filters( |
|
| 281 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
| 282 | - $this->css, |
|
| 283 | - $this |
|
| 284 | - ), |
|
| 285 | - 'header_js' => (array)apply_filters( |
|
| 286 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
| 287 | - $this->header_js, |
|
| 288 | - $this |
|
| 289 | - ), |
|
| 290 | - 'footer_js' => (array)apply_filters( |
|
| 291 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
| 292 | - $this->footer_js, |
|
| 293 | - $this |
|
| 294 | - ), |
|
| 295 | - 'eei18n' => apply_filters( |
|
| 296 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
| 297 | - \EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 298 | - $this |
|
| 299 | - ), |
|
| 300 | - 'notices' => \EEH_Template::display_template( |
|
| 301 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 302 | - array(), |
|
| 303 | - true |
|
| 304 | - ), |
|
| 305 | - ), |
|
| 306 | - true, |
|
| 307 | - true |
|
| 308 | - ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * localizeJsonVars |
|
| 315 | - * |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public function localizeJsonVars() |
|
| 319 | - { |
|
| 320 | - $JSON = ''; |
|
| 321 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 322 | - foreach ( (array)$vars as $key => $value ) { |
|
| 323 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars( $value ); |
|
| 324 | - } |
|
| 325 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
| 326 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 327 | - $JSON .= '; /* ]]> */'; |
|
| 328 | - } |
|
| 329 | - return $JSON; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * @param bool|int|float|string|array $var |
|
| 336 | - * @return array |
|
| 337 | - */ |
|
| 338 | - public function encodeJsonVars( $var ) |
|
| 339 | - { |
|
| 340 | - if ( is_array( $var ) ) { |
|
| 341 | - $localized_vars = array(); |
|
| 342 | - foreach ( (array)$var as $key => $value ) { |
|
| 343 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 344 | - } |
|
| 345 | - return $localized_vars; |
|
| 346 | - } else if ( is_scalar( $var ) ) { |
|
| 347 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 348 | - } |
|
| 349 | - return null; |
|
| 350 | - } |
|
| 61 | + protected $localized_vars = array(); |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Iframe constructor |
|
| 67 | + * |
|
| 68 | + * @param string $title |
|
| 69 | + * @param string $content |
|
| 70 | + * @throws \DomainException |
|
| 71 | + */ |
|
| 72 | + public function __construct( $title, $content ) |
|
| 73 | + { |
|
| 74 | + global $wp_version; |
|
| 75 | + if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 76 | + define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 77 | + } |
|
| 78 | + $this->setContent( $content ); |
|
| 79 | + $this->setTitle( $title ); |
|
| 80 | + $this->addStylesheets( |
|
| 81 | + apply_filters( |
|
| 82 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
| 83 | + array( |
|
| 84 | + 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 85 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
| 86 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 87 | + ), |
|
| 88 | + $this |
|
| 89 | + ) |
|
| 90 | + ); |
|
| 91 | + $this->addScripts( |
|
| 92 | + apply_filters( |
|
| 93 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
| 94 | + array( |
|
| 95 | + 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 96 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
| 97 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 98 | + ), |
|
| 99 | + $this |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + if ( |
|
| 103 | + apply_filters( |
|
| 104 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
| 105 | + false |
|
| 106 | + ) |
|
| 107 | + ) { |
|
| 108 | + $this->addStylesheets( |
|
| 109 | + apply_filters( |
|
| 110 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
| 111 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
| 112 | + $this |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param string $title |
|
| 122 | + * @throws \DomainException |
|
| 123 | + */ |
|
| 124 | + public function setTitle( $title ) |
|
| 125 | + { |
|
| 126 | + if ( empty( $title ) ) { |
|
| 127 | + throw new \DomainException( |
|
| 128 | + esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + $this->title = $title; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $content |
|
| 138 | + * @throws \DomainException |
|
| 139 | + */ |
|
| 140 | + public function setContent( $content ) |
|
| 141 | + { |
|
| 142 | + if ( empty( $content ) ) { |
|
| 143 | + throw new \DomainException( |
|
| 144 | + esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + $this->content = $content; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param boolean $enqueue_wp_assets |
|
| 154 | + */ |
|
| 155 | + public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 156 | + { |
|
| 157 | + $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param array $stylesheets |
|
| 164 | + * @throws \DomainException |
|
| 165 | + */ |
|
| 166 | + public function addStylesheets( array $stylesheets ) |
|
| 167 | + { |
|
| 168 | + if ( empty( $stylesheets ) ) { |
|
| 169 | + throw new \DomainException( |
|
| 170 | + esc_html__( |
|
| 171 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ) |
|
| 174 | + ); |
|
| 175 | + } |
|
| 176 | + foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 177 | + $this->css[ $handle ] = $stylesheet; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @param array $scripts |
|
| 185 | + * @param bool $add_to_header |
|
| 186 | + * @throws \DomainException |
|
| 187 | + */ |
|
| 188 | + public function addScripts( array $scripts, $add_to_header = false ) |
|
| 189 | + { |
|
| 190 | + if ( empty( $scripts ) ) { |
|
| 191 | + throw new \DomainException( |
|
| 192 | + esc_html__( |
|
| 193 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ) |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | + foreach ( $scripts as $handle => $script ) { |
|
| 199 | + if ( $add_to_header ) { |
|
| 200 | + $this->header_js[ $handle ] = $script; |
|
| 201 | + } else { |
|
| 202 | + $this->footer_js[ $handle ] = $script; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param array $vars |
|
| 211 | + * @param string $var_name |
|
| 212 | + * @throws \DomainException |
|
| 213 | + */ |
|
| 214 | + public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 215 | + { |
|
| 216 | + if ( empty( $vars ) ) { |
|
| 217 | + throw new \DomainException( |
|
| 218 | + esc_html__( |
|
| 219 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
| 220 | + 'event_espresso' |
|
| 221 | + ) |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | + foreach ( $vars as $handle => $var ) { |
|
| 225 | + if ( $var_name === 'eei18n' ) { |
|
| 226 | + \EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 227 | + } else { |
|
| 228 | + if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 229 | + $this->localized_vars[ $var_name ] = array(); |
|
| 230 | + } |
|
| 231 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param string $utm_content |
|
| 240 | + * @throws \DomainException |
|
| 241 | + */ |
|
| 242 | + public function display($utm_content = '') |
|
| 243 | + { |
|
| 244 | + $this->content .= \EEH_Template::powered_by_event_espresso( |
|
| 245 | + '', |
|
| 246 | + '', |
|
| 247 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
| 248 | + ); |
|
| 249 | + \EE_System::do_not_cache(); |
|
| 250 | + echo $this->getTemplate(); |
|
| 251 | + exit; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @return string |
|
| 258 | + * @throws \DomainException |
|
| 259 | + */ |
|
| 260 | + public function getTemplate() |
|
| 261 | + { |
|
| 262 | + return \EEH_Template::display_template( |
|
| 263 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 264 | + array( |
|
| 265 | + 'title' => apply_filters( |
|
| 266 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
| 267 | + $this->title, |
|
| 268 | + $this |
|
| 269 | + ), |
|
| 270 | + 'content' => apply_filters( |
|
| 271 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
| 272 | + $this->content, |
|
| 273 | + $this |
|
| 274 | + ), |
|
| 275 | + 'enqueue_wp_assets' => apply_filters( |
|
| 276 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
| 277 | + $this->enqueue_wp_assets, |
|
| 278 | + $this |
|
| 279 | + ), |
|
| 280 | + 'css' => (array)apply_filters( |
|
| 281 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
| 282 | + $this->css, |
|
| 283 | + $this |
|
| 284 | + ), |
|
| 285 | + 'header_js' => (array)apply_filters( |
|
| 286 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
| 287 | + $this->header_js, |
|
| 288 | + $this |
|
| 289 | + ), |
|
| 290 | + 'footer_js' => (array)apply_filters( |
|
| 291 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
| 292 | + $this->footer_js, |
|
| 293 | + $this |
|
| 294 | + ), |
|
| 295 | + 'eei18n' => apply_filters( |
|
| 296 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
| 297 | + \EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 298 | + $this |
|
| 299 | + ), |
|
| 300 | + 'notices' => \EEH_Template::display_template( |
|
| 301 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 302 | + array(), |
|
| 303 | + true |
|
| 304 | + ), |
|
| 305 | + ), |
|
| 306 | + true, |
|
| 307 | + true |
|
| 308 | + ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * localizeJsonVars |
|
| 315 | + * |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public function localizeJsonVars() |
|
| 319 | + { |
|
| 320 | + $JSON = ''; |
|
| 321 | + foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 322 | + foreach ( (array)$vars as $key => $value ) { |
|
| 323 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars( $value ); |
|
| 324 | + } |
|
| 325 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
| 326 | + $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 327 | + $JSON .= '; /* ]]> */'; |
|
| 328 | + } |
|
| 329 | + return $JSON; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @param bool|int|float|string|array $var |
|
| 336 | + * @return array |
|
| 337 | + */ |
|
| 338 | + public function encodeJsonVars( $var ) |
|
| 339 | + { |
|
| 340 | + if ( is_array( $var ) ) { |
|
| 341 | + $localized_vars = array(); |
|
| 342 | + foreach ( (array)$var as $key => $value ) { |
|
| 343 | + $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 344 | + } |
|
| 345 | + return $localized_vars; |
|
| 346 | + } else if ( is_scalar( $var ) ) { |
|
| 347 | + return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 348 | + } |
|
| 349 | + return null; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | 352 | |
| 353 | 353 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\iframe_display; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -69,21 +69,21 @@ discard block |
||
| 69 | 69 | * @param string $content |
| 70 | 70 | * @throws \DomainException |
| 71 | 71 | */ |
| 72 | - public function __construct( $title, $content ) |
|
| 72 | + public function __construct($title, $content) |
|
| 73 | 73 | { |
| 74 | 74 | global $wp_version; |
| 75 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
| 76 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 75 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
| 76 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
| 77 | 77 | } |
| 78 | - $this->setContent( $content ); |
|
| 79 | - $this->setTitle( $title ); |
|
| 78 | + $this->setContent($content); |
|
| 79 | + $this->setTitle($title); |
|
| 80 | 80 | $this->addStylesheets( |
| 81 | 81 | apply_filters( |
| 82 | 82 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
| 83 | 83 | array( |
| 84 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
| 84 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
| 85 | 85 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
| 86 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 86 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
| 87 | 87 | ), |
| 88 | 88 | $this |
| 89 | 89 | ) |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | apply_filters( |
| 93 | 93 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
| 94 | 94 | array( |
| 95 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
| 95 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
| 96 | 96 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
| 97 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
| 97 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
| 98 | 98 | ), |
| 99 | 99 | $this |
| 100 | 100 | ) |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * @param string $title |
| 122 | 122 | * @throws \DomainException |
| 123 | 123 | */ |
| 124 | - public function setTitle( $title ) |
|
| 124 | + public function setTitle($title) |
|
| 125 | 125 | { |
| 126 | - if ( empty( $title ) ) { |
|
| 126 | + if (empty($title)) { |
|
| 127 | 127 | throw new \DomainException( |
| 128 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
| 128 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
| 129 | 129 | ); |
| 130 | 130 | } |
| 131 | 131 | $this->title = $title; |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * @param string $content |
| 138 | 138 | * @throws \DomainException |
| 139 | 139 | */ |
| 140 | - public function setContent( $content ) |
|
| 140 | + public function setContent($content) |
|
| 141 | 141 | { |
| 142 | - if ( empty( $content ) ) { |
|
| 142 | + if (empty($content)) { |
|
| 143 | 143 | throw new \DomainException( |
| 144 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
| 144 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | 147 | $this->content = $content; |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | /** |
| 153 | 153 | * @param boolean $enqueue_wp_assets |
| 154 | 154 | */ |
| 155 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
| 155 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
| 156 | 156 | { |
| 157 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
| 157 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * @param array $stylesheets |
| 164 | 164 | * @throws \DomainException |
| 165 | 165 | */ |
| 166 | - public function addStylesheets( array $stylesheets ) |
|
| 166 | + public function addStylesheets(array $stylesheets) |
|
| 167 | 167 | { |
| 168 | - if ( empty( $stylesheets ) ) { |
|
| 168 | + if (empty($stylesheets)) { |
|
| 169 | 169 | throw new \DomainException( |
| 170 | 170 | esc_html__( |
| 171 | 171 | 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | ) |
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
| 177 | - $this->css[ $handle ] = $stylesheet; |
|
| 176 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
| 177 | + $this->css[$handle] = $stylesheet; |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -185,9 +185,9 @@ discard block |
||
| 185 | 185 | * @param bool $add_to_header |
| 186 | 186 | * @throws \DomainException |
| 187 | 187 | */ |
| 188 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
| 188 | + public function addScripts(array $scripts, $add_to_header = false) |
|
| 189 | 189 | { |
| 190 | - if ( empty( $scripts ) ) { |
|
| 190 | + if (empty($scripts)) { |
|
| 191 | 191 | throw new \DomainException( |
| 192 | 192 | esc_html__( |
| 193 | 193 | 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | ) |
| 196 | 196 | ); |
| 197 | 197 | } |
| 198 | - foreach ( $scripts as $handle => $script ) { |
|
| 199 | - if ( $add_to_header ) { |
|
| 200 | - $this->header_js[ $handle ] = $script; |
|
| 198 | + foreach ($scripts as $handle => $script) { |
|
| 199 | + if ($add_to_header) { |
|
| 200 | + $this->header_js[$handle] = $script; |
|
| 201 | 201 | } else { |
| 202 | - $this->footer_js[ $handle ] = $script; |
|
| 202 | + $this->footer_js[$handle] = $script; |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | * @param string $var_name |
| 212 | 212 | * @throws \DomainException |
| 213 | 213 | */ |
| 214 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
| 214 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
| 215 | 215 | { |
| 216 | - if ( empty( $vars ) ) { |
|
| 216 | + if (empty($vars)) { |
|
| 217 | 217 | throw new \DomainException( |
| 218 | 218 | esc_html__( |
| 219 | 219 | 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | ) |
| 222 | 222 | ); |
| 223 | 223 | } |
| 224 | - foreach ( $vars as $handle => $var ) { |
|
| 225 | - if ( $var_name === 'eei18n' ) { |
|
| 226 | - \EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
| 224 | + foreach ($vars as $handle => $var) { |
|
| 225 | + if ($var_name === 'eei18n') { |
|
| 226 | + \EE_Registry::$i18n_js_strings[$handle] = $var; |
|
| 227 | 227 | } else { |
| 228 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
| 229 | - $this->localized_vars[ $var_name ] = array(); |
|
| 228 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
| 229 | + $this->localized_vars[$var_name] = array(); |
|
| 230 | 230 | } |
| 231 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
| 231 | + $this->localized_vars[$var_name][$handle] = $var; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | public function getTemplate() |
| 261 | 261 | { |
| 262 | 262 | return \EEH_Template::display_template( |
| 263 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
| 263 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
| 264 | 264 | array( |
| 265 | 265 | 'title' => apply_filters( |
| 266 | 266 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -277,28 +277,28 @@ discard block |
||
| 277 | 277 | $this->enqueue_wp_assets, |
| 278 | 278 | $this |
| 279 | 279 | ), |
| 280 | - 'css' => (array)apply_filters( |
|
| 280 | + 'css' => (array) apply_filters( |
|
| 281 | 281 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
| 282 | 282 | $this->css, |
| 283 | 283 | $this |
| 284 | 284 | ), |
| 285 | - 'header_js' => (array)apply_filters( |
|
| 285 | + 'header_js' => (array) apply_filters( |
|
| 286 | 286 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
| 287 | 287 | $this->header_js, |
| 288 | 288 | $this |
| 289 | 289 | ), |
| 290 | - 'footer_js' => (array)apply_filters( |
|
| 290 | + 'footer_js' => (array) apply_filters( |
|
| 291 | 291 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
| 292 | 292 | $this->footer_js, |
| 293 | 293 | $this |
| 294 | 294 | ), |
| 295 | 295 | 'eei18n' => apply_filters( |
| 296 | 296 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
| 297 | - \EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
| 297 | + \EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
| 298 | 298 | $this |
| 299 | 299 | ), |
| 300 | 300 | 'notices' => \EEH_Template::display_template( |
| 301 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
| 301 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
| 302 | 302 | array(), |
| 303 | 303 | true |
| 304 | 304 | ), |
@@ -318,12 +318,12 @@ discard block |
||
| 318 | 318 | public function localizeJsonVars() |
| 319 | 319 | { |
| 320 | 320 | $JSON = ''; |
| 321 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
| 322 | - foreach ( (array)$vars as $key => $value ) { |
|
| 323 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars( $value ); |
|
| 321 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
| 322 | + foreach ((array) $vars as $key => $value) { |
|
| 323 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($value); |
|
| 324 | 324 | } |
| 325 | 325 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
| 326 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
| 326 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
| 327 | 327 | $JSON .= '; /* ]]> */'; |
| 328 | 328 | } |
| 329 | 329 | return $JSON; |
@@ -335,16 +335,16 @@ discard block |
||
| 335 | 335 | * @param bool|int|float|string|array $var |
| 336 | 336 | * @return array |
| 337 | 337 | */ |
| 338 | - public function encodeJsonVars( $var ) |
|
| 338 | + public function encodeJsonVars($var) |
|
| 339 | 339 | { |
| 340 | - if ( is_array( $var ) ) { |
|
| 340 | + if (is_array($var)) { |
|
| 341 | 341 | $localized_vars = array(); |
| 342 | - foreach ( (array)$var as $key => $value ) { |
|
| 343 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
| 342 | + foreach ((array) $var as $key => $value) { |
|
| 343 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
| 344 | 344 | } |
| 345 | 345 | return $localized_vars; |
| 346 | - } else if ( is_scalar( $var ) ) { |
|
| 347 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
| 346 | + } else if (is_scalar($var)) { |
|
| 347 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
| 348 | 348 | } |
| 349 | 349 | return null; |
| 350 | 350 | } |
@@ -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 | * Event Espresso |
@@ -28,2119 +28,2119 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - //set in _init_page_props() |
|
| 32 | - public $page_slug; |
|
| 31 | + //set in _init_page_props() |
|
| 32 | + public $page_slug; |
|
| 33 | 33 | |
| 34 | - public $page_label; |
|
| 34 | + public $page_label; |
|
| 35 | 35 | |
| 36 | - public $page_folder; |
|
| 36 | + public $page_folder; |
|
| 37 | 37 | |
| 38 | - //set in define_page_props() |
|
| 39 | - protected $_admin_base_url; |
|
| 38 | + //set in define_page_props() |
|
| 39 | + protected $_admin_base_url; |
|
| 40 | 40 | |
| 41 | - protected $_admin_base_path; |
|
| 41 | + protected $_admin_base_path; |
|
| 42 | 42 | |
| 43 | - protected $_admin_page_title; |
|
| 43 | + protected $_admin_page_title; |
|
| 44 | 44 | |
| 45 | - protected $_labels; |
|
| 45 | + protected $_labels; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - //set early within EE_Admin_Init |
|
| 49 | - protected $_wp_page_slug; |
|
| 48 | + //set early within EE_Admin_Init |
|
| 49 | + protected $_wp_page_slug; |
|
| 50 | 50 | |
| 51 | - //navtabs |
|
| 52 | - protected $_nav_tabs; |
|
| 51 | + //navtabs |
|
| 52 | + protected $_nav_tabs; |
|
| 53 | 53 | |
| 54 | - protected $_default_nav_tab_name; |
|
| 54 | + protected $_default_nav_tab_name; |
|
| 55 | 55 | |
| 56 | - //helptourstops |
|
| 57 | - protected $_help_tour = array(); |
|
| 56 | + //helptourstops |
|
| 57 | + protected $_help_tour = array(); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - //template variables (used by templates) |
|
| 61 | - protected $_template_path; |
|
| 60 | + //template variables (used by templates) |
|
| 61 | + protected $_template_path; |
|
| 62 | 62 | |
| 63 | - protected $_column_template_path; |
|
| 63 | + protected $_column_template_path; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array $_template_args |
|
| 67 | - */ |
|
| 68 | - protected $_template_args = array(); |
|
| 65 | + /** |
|
| 66 | + * @var array $_template_args |
|
| 67 | + */ |
|
| 68 | + protected $_template_args = array(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * this will hold the list table object for a given view. |
|
| 72 | - * |
|
| 73 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | - */ |
|
| 75 | - protected $_list_table_object; |
|
| 70 | + /** |
|
| 71 | + * this will hold the list table object for a given view. |
|
| 72 | + * |
|
| 73 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | + */ |
|
| 75 | + protected $_list_table_object; |
|
| 76 | 76 | |
| 77 | - //bools |
|
| 78 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 77 | + //bools |
|
| 78 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 79 | 79 | |
| 80 | - protected $_routing; |
|
| 80 | + protected $_routing; |
|
| 81 | 81 | |
| 82 | - //list table args |
|
| 83 | - protected $_view; |
|
| 82 | + //list table args |
|
| 83 | + protected $_view; |
|
| 84 | 84 | |
| 85 | - protected $_views; |
|
| 85 | + protected $_views; |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - //action => method pairs used for routing incoming requests |
|
| 89 | - protected $_page_routes; |
|
| 88 | + //action => method pairs used for routing incoming requests |
|
| 89 | + protected $_page_routes; |
|
| 90 | 90 | |
| 91 | - protected $_page_config; |
|
| 91 | + protected $_page_config; |
|
| 92 | 92 | |
| 93 | - //the current page route and route config |
|
| 94 | - protected $_route; |
|
| 93 | + //the current page route and route config |
|
| 94 | + protected $_route; |
|
| 95 | 95 | |
| 96 | - protected $_route_config; |
|
| 96 | + protected $_route_config; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | - * actions. |
|
| 101 | - * |
|
| 102 | - * @since 4.6.x |
|
| 103 | - * @var array. |
|
| 104 | - */ |
|
| 105 | - protected $_default_route_query_args; |
|
| 98 | + /** |
|
| 99 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | + * actions. |
|
| 101 | + * |
|
| 102 | + * @since 4.6.x |
|
| 103 | + * @var array. |
|
| 104 | + */ |
|
| 105 | + protected $_default_route_query_args; |
|
| 106 | 106 | |
| 107 | - //set via request page and action args. |
|
| 108 | - protected $_current_page; |
|
| 107 | + //set via request page and action args. |
|
| 108 | + protected $_current_page; |
|
| 109 | 109 | |
| 110 | - protected $_current_view; |
|
| 110 | + protected $_current_view; |
|
| 111 | 111 | |
| 112 | - protected $_current_page_view_url; |
|
| 112 | + protected $_current_page_view_url; |
|
| 113 | 113 | |
| 114 | - //sanitized request action (and nonce) |
|
| 115 | - /** |
|
| 116 | - * @var string $_req_action |
|
| 117 | - */ |
|
| 118 | - protected $_req_action; |
|
| 114 | + //sanitized request action (and nonce) |
|
| 115 | + /** |
|
| 116 | + * @var string $_req_action |
|
| 117 | + */ |
|
| 118 | + protected $_req_action; |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @var string $_req_nonce |
|
| 122 | - */ |
|
| 123 | - protected $_req_nonce; |
|
| 120 | + /** |
|
| 121 | + * @var string $_req_nonce |
|
| 122 | + */ |
|
| 123 | + protected $_req_nonce; |
|
| 124 | 124 | |
| 125 | - //search related |
|
| 126 | - protected $_search_btn_label; |
|
| 125 | + //search related |
|
| 126 | + protected $_search_btn_label; |
|
| 127 | 127 | |
| 128 | - protected $_search_box_callback; |
|
| 128 | + protected $_search_box_callback; |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * WP Current Screen object |
|
| 132 | - * |
|
| 133 | - * @var WP_Screen |
|
| 134 | - */ |
|
| 135 | - protected $_current_screen; |
|
| 130 | + /** |
|
| 131 | + * WP Current Screen object |
|
| 132 | + * |
|
| 133 | + * @var WP_Screen |
|
| 134 | + */ |
|
| 135 | + protected $_current_screen; |
|
| 136 | 136 | |
| 137 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | - protected $_hook_obj; |
|
| 137 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | + protected $_hook_obj; |
|
| 139 | 139 | |
| 140 | - //for holding incoming request data |
|
| 141 | - protected $_req_data; |
|
| 140 | + //for holding incoming request data |
|
| 141 | + protected $_req_data; |
|
| 142 | 142 | |
| 143 | - // yes / no array for admin form fields |
|
| 144 | - protected $_yes_no_values = array(); |
|
| 145 | - |
|
| 146 | - //some default things shared by all child classes |
|
| 147 | - protected $_default_espresso_metaboxes; |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * EE_Registry Object |
|
| 151 | - * |
|
| 152 | - * @var EE_Registry |
|
| 153 | - * @access protected |
|
| 154 | - */ |
|
| 155 | - protected $EE = null; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | - * |
|
| 162 | - * @var boolean |
|
| 163 | - */ |
|
| 164 | - protected $_is_caf = false; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @Constructor |
|
| 170 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | - * @access public |
|
| 172 | - */ |
|
| 173 | - public function __construct($routing = true) |
|
| 174 | - { |
|
| 175 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | - $this->_is_caf = true; |
|
| 177 | - } |
|
| 178 | - $this->_yes_no_values = array( |
|
| 179 | - array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | - array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | - ); |
|
| 182 | - //set the _req_data property. |
|
| 183 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | - //routing enabled? |
|
| 185 | - $this->_routing = $routing; |
|
| 186 | - //set initial page props (child method) |
|
| 187 | - $this->_init_page_props(); |
|
| 188 | - //set global defaults |
|
| 189 | - $this->_set_defaults(); |
|
| 190 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | - $this->_global_ajax_hooks(); |
|
| 192 | - $this->_ajax_hooks(); |
|
| 193 | - //other_page_hooks have to be early too. |
|
| 194 | - $this->_do_other_page_hooks(); |
|
| 195 | - //This just allows us to have extending clases do something specific before the parent constructor runs _page_setup. |
|
| 196 | - if (method_exists($this, '_before_page_setup')) { |
|
| 197 | - $this->_before_page_setup(); |
|
| 198 | - } |
|
| 199 | - //set up page dependencies |
|
| 200 | - $this->_page_setup(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * _init_page_props |
|
| 207 | - * Child classes use to set at least the following properties: |
|
| 208 | - * $page_slug. |
|
| 209 | - * $page_label. |
|
| 210 | - * |
|
| 211 | - * @abstract |
|
| 212 | - * @access protected |
|
| 213 | - * @return void |
|
| 214 | - */ |
|
| 215 | - abstract protected function _init_page_props(); |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * _ajax_hooks |
|
| 221 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 222 | - * Note: within the ajax callback methods. |
|
| 223 | - * |
|
| 224 | - * @abstract |
|
| 225 | - * @access protected |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - abstract protected function _ajax_hooks(); |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _define_page_props |
|
| 234 | - * child classes define page properties in here. Must include at least: |
|
| 235 | - * $_admin_base_url = base_url for all admin pages |
|
| 236 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 237 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 238 | - * array( |
|
| 239 | - * 'buttons' => array( |
|
| 240 | - * 'add' => __('label for add new button'), |
|
| 241 | - * 'edit' => __('label for edit button'), |
|
| 242 | - * 'delete' => __('label for delete button') |
|
| 243 | - * ) |
|
| 244 | - * ) |
|
| 245 | - * |
|
| 246 | - * @abstract |
|
| 247 | - * @access protected |
|
| 248 | - * @return void |
|
| 249 | - */ |
|
| 250 | - abstract protected function _define_page_props(); |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * _set_page_routes |
|
| 256 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 257 | - * route. Here's the format |
|
| 258 | - * $this->_page_routes = array( |
|
| 259 | - * 'default' => array( |
|
| 260 | - * 'func' => '_default_method_handling_route', |
|
| 261 | - * 'args' => array('array','of','args'), |
|
| 262 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 263 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 264 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 265 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 266 | - * ), |
|
| 267 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 268 | - * ) |
|
| 269 | - * ) |
|
| 270 | - * |
|
| 271 | - * @abstract |
|
| 272 | - * @access protected |
|
| 273 | - * @return void |
|
| 274 | - */ |
|
| 275 | - abstract protected function _set_page_routes(); |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * _set_page_config |
|
| 281 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 282 | - * Format: |
|
| 283 | - * $this->_page_config = array( |
|
| 284 | - * 'default' => array( |
|
| 285 | - * 'labels' => array( |
|
| 286 | - * 'buttons' => array( |
|
| 287 | - * 'add' => __('label for adding item'), |
|
| 288 | - * 'edit' => __('label for editing item'), |
|
| 289 | - * 'delete' => __('label for deleting item') |
|
| 290 | - * ), |
|
| 291 | - * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 292 | - * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 293 | - * 'nav' => array( |
|
| 294 | - * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 295 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 296 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 297 | - * 'order' => 10, //required to indicate tab position. |
|
| 298 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 299 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 300 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 301 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 302 | - * this flag to make sure the necessary js gets enqueued on page load. |
|
| 303 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 304 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 305 | - * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 306 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 307 | - * 'tab_id' => array( |
|
| 308 | - * 'title' => 'tab_title', |
|
| 309 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 310 | - * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 311 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 312 | - * ), |
|
| 313 | - * 'tab2_id' => array( |
|
| 314 | - * 'title' => 'tab2 title', |
|
| 315 | - * 'filename' => 'file_name_2' |
|
| 316 | - * 'callback' => 'callback_method_for_content', |
|
| 317 | - * ), |
|
| 318 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 319 | - * 'help_tour' => array( |
|
| 320 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 321 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 322 | - * ), |
|
| 323 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 324 | - * 'require_nonce' to FALSE |
|
| 325 | - * ) |
|
| 326 | - * ) |
|
| 327 | - * |
|
| 328 | - * @abstract |
|
| 329 | - * @access protected |
|
| 330 | - * @return void |
|
| 331 | - */ |
|
| 332 | - abstract protected function _set_page_config(); |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** end sample help_tour methods **/ |
|
| 339 | - /** |
|
| 340 | - * _add_screen_options |
|
| 341 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 342 | - * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 343 | - * |
|
| 344 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 345 | - * see also WP_Screen object documents... |
|
| 346 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 347 | - * @abstract |
|
| 348 | - * @access protected |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - abstract protected function _add_screen_options(); |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * _add_feature_pointers |
|
| 357 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 358 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 359 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 360 | - * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 361 | - * |
|
| 362 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 363 | - * @abstract |
|
| 364 | - * @access protected |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - abstract protected function _add_feature_pointers(); |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * load_scripts_styles |
|
| 373 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 374 | - * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 375 | - * |
|
| 376 | - * @abstract |
|
| 377 | - * @access public |
|
| 378 | - * @return void |
|
| 379 | - */ |
|
| 380 | - abstract public function load_scripts_styles(); |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * admin_init |
|
| 386 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 387 | - * |
|
| 388 | - * @abstract |
|
| 389 | - * @access public |
|
| 390 | - * @return void |
|
| 391 | - */ |
|
| 392 | - abstract public function admin_init(); |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * admin_notices |
|
| 398 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 399 | - * |
|
| 400 | - * @abstract |
|
| 401 | - * @access public |
|
| 402 | - * @return void |
|
| 403 | - */ |
|
| 404 | - abstract public function admin_notices(); |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * admin_footer_scripts |
|
| 410 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 411 | - * |
|
| 412 | - * @access public |
|
| 413 | - * @return void |
|
| 414 | - */ |
|
| 415 | - abstract public function admin_footer_scripts(); |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * admin_footer |
|
| 421 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 422 | - * |
|
| 423 | - * @access public |
|
| 424 | - * @return void |
|
| 425 | - */ |
|
| 426 | - public function admin_footer() |
|
| 427 | - { |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * _global_ajax_hooks |
|
| 434 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 435 | - * Note: within the ajax callback methods. |
|
| 436 | - * |
|
| 437 | - * @abstract |
|
| 438 | - * @access protected |
|
| 439 | - * @return void |
|
| 440 | - */ |
|
| 441 | - protected function _global_ajax_hooks() |
|
| 442 | - { |
|
| 443 | - //for lazy loading of metabox content |
|
| 444 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - public function ajax_metabox_content() |
|
| 450 | - { |
|
| 451 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 452 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 453 | - self::cached_rss_display($contentid, $url); |
|
| 454 | - wp_die(); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * _page_setup |
|
| 461 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 462 | - * |
|
| 463 | - * @final |
|
| 464 | - * @access protected |
|
| 465 | - * @return void |
|
| 466 | - */ |
|
| 467 | - final protected function _page_setup() |
|
| 468 | - { |
|
| 469 | - //requires? |
|
| 470 | - //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 471 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 472 | - //next verify if we need to load anything... |
|
| 473 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 474 | - $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 475 | - global $ee_menu_slugs; |
|
| 476 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 477 | - if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 478 | - return false; |
|
| 479 | - } |
|
| 480 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 481 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 482 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 483 | - } |
|
| 484 | - // then set blank or -1 action values to 'default' |
|
| 485 | - $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 486 | - //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 487 | - $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 488 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 489 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 490 | - $this->_current_view = $this->_req_action; |
|
| 491 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 492 | - $this->_define_page_props(); |
|
| 493 | - $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 494 | - //default things |
|
| 495 | - $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 496 | - //set page configs |
|
| 497 | - $this->_set_page_routes(); |
|
| 498 | - $this->_set_page_config(); |
|
| 499 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 500 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 501 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 502 | - } |
|
| 503 | - //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 504 | - if (method_exists($this, '_extend_page_config')) { |
|
| 505 | - $this->_extend_page_config(); |
|
| 506 | - } |
|
| 507 | - //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 508 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 509 | - $this->_extend_page_config_for_cpt(); |
|
| 510 | - } |
|
| 511 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 512 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 515 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 517 | - } |
|
| 518 | - //next route only if routing enabled |
|
| 519 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 520 | - $this->_verify_routes(); |
|
| 521 | - //next let's just check user_access and kill if no access |
|
| 522 | - $this->check_user_access(); |
|
| 523 | - if ($this->_is_UI_request) { |
|
| 524 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 525 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 526 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 528 | - } |
|
| 529 | - } else { |
|
| 530 | - //hijack regular WP loading and route admin request immediately |
|
| 531 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 532 | - $this->route_admin_request(); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 541 | - * |
|
| 542 | - * @access private |
|
| 543 | - * @return void |
|
| 544 | - */ |
|
| 545 | - private function _do_other_page_hooks() |
|
| 546 | - { |
|
| 547 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 548 | - foreach ($registered_pages as $page) { |
|
| 549 | - //now let's setup the file name and class that should be present |
|
| 550 | - $classname = str_replace('.class.php', '', $page); |
|
| 551 | - //autoloaders should take care of loading file |
|
| 552 | - if ( ! class_exists($classname)) { |
|
| 553 | - $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | - $error_msg[] = $error_msg[0] |
|
| 555 | - . "\r\n" |
|
| 556 | - . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | - 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 558 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 559 | - } |
|
| 560 | - $a = new ReflectionClass($classname); |
|
| 561 | - //notice we are passing the instance of this class to the hook object. |
|
| 562 | - $hookobj[] = $a->newInstance($this); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - public function load_page_dependencies() |
|
| 569 | - { |
|
| 570 | - try { |
|
| 571 | - $this->_load_page_dependencies(); |
|
| 572 | - } catch (EE_Error $e) { |
|
| 573 | - $e->get_error(); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * load_page_dependencies |
|
| 581 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 582 | - * |
|
| 583 | - * @access public |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - protected function _load_page_dependencies() |
|
| 587 | - { |
|
| 588 | - //let's set the current_screen and screen options to override what WP set |
|
| 589 | - $this->_current_screen = get_current_screen(); |
|
| 590 | - //load admin_notices - global, page class, and view specific |
|
| 591 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 592 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 593 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 595 | - } |
|
| 596 | - //load network admin_notices - global, page class, and view specific |
|
| 597 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 598 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 600 | - } |
|
| 601 | - //this will save any per_page screen options if they are present |
|
| 602 | - $this->_set_per_page_screen_options(); |
|
| 603 | - //setup list table properties |
|
| 604 | - $this->_set_list_table(); |
|
| 605 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 606 | - $this->_add_registered_meta_boxes(); |
|
| 607 | - $this->_add_screen_columns(); |
|
| 608 | - //add screen options - global, page child class, and view specific |
|
| 609 | - $this->_add_global_screen_options(); |
|
| 610 | - $this->_add_screen_options(); |
|
| 611 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 613 | - } |
|
| 614 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 615 | - $this->_add_help_tour(); |
|
| 616 | - $this->_add_help_tabs(); |
|
| 617 | - $this->_add_qtips(); |
|
| 618 | - //add feature_pointers - global, page child class, and view specific |
|
| 619 | - $this->_add_feature_pointers(); |
|
| 620 | - $this->_add_global_feature_pointers(); |
|
| 621 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 623 | - } |
|
| 624 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 625 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 626 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 627 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 629 | - } |
|
| 630 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 631 | - //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 632 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 633 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 634 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 636 | - } |
|
| 637 | - //admin footer scripts |
|
| 638 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 639 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 640 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 642 | - } |
|
| 643 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 644 | - //targeted hook |
|
| 645 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * _set_defaults |
|
| 652 | - * This sets some global defaults for class properties. |
|
| 653 | - */ |
|
| 654 | - private function _set_defaults() |
|
| 655 | - { |
|
| 656 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 657 | - $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 658 | - $this->default_nav_tab_name = 'overview'; |
|
| 659 | - //init template args |
|
| 660 | - $this->_template_args = array( |
|
| 661 | - 'admin_page_header' => '', |
|
| 662 | - 'admin_page_content' => '', |
|
| 663 | - 'post_body_content' => '', |
|
| 664 | - 'before_list_table' => '', |
|
| 665 | - 'after_list_table' => '', |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * route_admin_request |
|
| 673 | - * |
|
| 674 | - * @see _route_admin_request() |
|
| 675 | - * @access public |
|
| 676 | - * @return void|exception error |
|
| 677 | - */ |
|
| 678 | - public function route_admin_request() |
|
| 679 | - { |
|
| 680 | - try { |
|
| 681 | - $this->_route_admin_request(); |
|
| 682 | - } catch (EE_Error $e) { |
|
| 683 | - $e->get_error(); |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function set_wp_page_slug($wp_page_slug) |
|
| 690 | - { |
|
| 691 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 692 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 693 | - if (is_network_admin()) { |
|
| 694 | - $this->_wp_page_slug .= '-network'; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * _verify_routes |
|
| 702 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 703 | - * |
|
| 704 | - * @access protected |
|
| 705 | - * @return void |
|
| 706 | - */ |
|
| 707 | - protected function _verify_routes() |
|
| 708 | - { |
|
| 709 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 710 | - if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 711 | - return false; |
|
| 712 | - } |
|
| 713 | - $this->_route = false; |
|
| 714 | - $func = false; |
|
| 715 | - $args = array(); |
|
| 716 | - // check that the page_routes array is not empty |
|
| 717 | - if (empty($this->_page_routes)) { |
|
| 718 | - // user error msg |
|
| 719 | - $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 720 | - // developer error msg |
|
| 721 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | - throw new EE_Error($error_msg); |
|
| 723 | - } |
|
| 724 | - // and that the requested page route exists |
|
| 725 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 726 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 727 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 728 | - } else { |
|
| 729 | - // user error msg |
|
| 730 | - $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 731 | - // developer error msg |
|
| 732 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | - throw new EE_Error($error_msg); |
|
| 734 | - } |
|
| 735 | - // and that a default route exists |
|
| 736 | - if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 737 | - // user error msg |
|
| 738 | - $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 739 | - // developer error msg |
|
| 740 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | - throw new EE_Error($error_msg); |
|
| 742 | - } |
|
| 743 | - //first lets' catch if the UI request has EVER been set. |
|
| 744 | - if ($this->_is_UI_request === null) { |
|
| 745 | - //lets set if this is a UI request or not. |
|
| 746 | - $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 747 | - //wait a minute... we might have a noheader in the route array |
|
| 748 | - $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 749 | - } |
|
| 750 | - $this->_set_current_labels(); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 757 | - * |
|
| 758 | - * @param string $route the route name we're verifying |
|
| 759 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 760 | - */ |
|
| 761 | - protected function _verify_route($route) |
|
| 762 | - { |
|
| 763 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 764 | - return true; |
|
| 765 | - } else { |
|
| 766 | - // user error msg |
|
| 767 | - $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 768 | - // developer error msg |
|
| 769 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | - throw new EE_Error($error_msg); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * perform nonce verification |
|
| 778 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 779 | - * |
|
| 780 | - * @param string $nonce The nonce sent |
|
| 781 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 782 | - * @return mixed (bool|die) |
|
| 783 | - */ |
|
| 784 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 785 | - { |
|
| 786 | - // verify nonce against expected value |
|
| 787 | - if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 788 | - // these are not the droids you are looking for !!! |
|
| 789 | - $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 790 | - if (WP_DEBUG) { |
|
| 791 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | - } |
|
| 793 | - if ( ! defined('DOING_AJAX')) { |
|
| 794 | - wp_die($msg); |
|
| 795 | - } else { |
|
| 796 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | - $this->_return_json(); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - /** |
|
| 805 | - * _route_admin_request() |
|
| 806 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 807 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 808 | - * in the page routes and then will try to load the corresponding method. |
|
| 809 | - * |
|
| 810 | - * @access protected |
|
| 811 | - * @return void |
|
| 812 | - * @throws \EE_Error |
|
| 813 | - */ |
|
| 814 | - protected function _route_admin_request() |
|
| 815 | - { |
|
| 816 | - if ( ! $this->_is_UI_request) { |
|
| 817 | - $this->_verify_routes(); |
|
| 818 | - } |
|
| 819 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 820 | - ? $this->_route_config['require_nonce'] |
|
| 821 | - : true; |
|
| 822 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 823 | - // set nonce from post data |
|
| 824 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 825 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 826 | - : ''; |
|
| 827 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 828 | - } |
|
| 829 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 830 | - if ($this->_is_UI_request) { |
|
| 831 | - $this->_set_nav_tabs(); |
|
| 832 | - } |
|
| 833 | - // grab callback function |
|
| 834 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 835 | - // check if callback has args |
|
| 836 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 837 | - $error_msg = ''; |
|
| 838 | - // action right before calling route |
|
| 839 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 840 | - if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 841 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 842 | - } |
|
| 843 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 844 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 845 | - $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 846 | - if ( ! empty($func)) { |
|
| 847 | - if (is_array($func)) { |
|
| 848 | - list($class, $method) = $func; |
|
| 849 | - } else if (strpos($func, '::') !== false) { |
|
| 850 | - list($class, $method) = explode('::', $func); |
|
| 851 | - } else { |
|
| 852 | - $class = $this; |
|
| 853 | - $method = $func; |
|
| 854 | - } |
|
| 855 | - if ( ! (is_object($class) && $class === $this)) { |
|
| 856 | - // send along this admin page object for access by addons. |
|
| 857 | - $args['admin_page_object'] = $this; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - if ( |
|
| 861 | - //is it a method on a class that doesn't work? |
|
| 862 | - ( |
|
| 863 | - ( |
|
| 864 | - method_exists($class, $method) |
|
| 865 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 866 | - ) |
|
| 867 | - && ( |
|
| 868 | - //is it a standalone function that doesn't work? |
|
| 869 | - function_exists($method) |
|
| 870 | - && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 871 | - ) |
|
| 872 | - ) |
|
| 873 | - || ( |
|
| 874 | - //is it neither a class method NOR a standalone function? |
|
| 875 | - ! method_exists($class, $method) |
|
| 876 | - && ! function_exists($method) |
|
| 877 | - ) |
|
| 878 | - ) { |
|
| 879 | - // user error msg |
|
| 880 | - $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 881 | - // developer error msg |
|
| 882 | - $error_msg .= '||'; |
|
| 883 | - $error_msg .= sprintf( |
|
| 884 | - __( |
|
| 885 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 886 | - 'event_espresso' |
|
| 887 | - ), |
|
| 888 | - $method |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - if ( ! empty($error_msg)) { |
|
| 892 | - throw new EE_Error($error_msg); |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 896 | - //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 897 | - if ($this->_is_UI_request === false |
|
| 898 | - && is_array($this->_route) |
|
| 899 | - && ! empty($this->_route['headers_sent_route']) |
|
| 900 | - ) { |
|
| 901 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 909 | - * route redirects to a headers route in its route config. |
|
| 910 | - * |
|
| 911 | - * @since 4.3.0 |
|
| 912 | - * @param string $new_route New (non header) route to redirect to. |
|
| 913 | - * @return void |
|
| 914 | - */ |
|
| 915 | - protected function _reset_routing_properties($new_route) |
|
| 916 | - { |
|
| 917 | - $this->_is_UI_request = true; |
|
| 918 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 919 | - $this->_req_data['action'] = $new_route; |
|
| 920 | - //rerun page setup |
|
| 921 | - $this->_page_setup(); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * _add_query_arg |
|
| 928 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 929 | - *(internally just uses EEH_URL's function with the same name) |
|
| 930 | - * |
|
| 931 | - * @access public |
|
| 932 | - * @param array $args |
|
| 933 | - * @param string $url |
|
| 934 | - * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 935 | - * url in an associative array indexed by the key 'wp_referer'; |
|
| 936 | - * Example usage: |
|
| 937 | - * If the current page is: |
|
| 938 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 939 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 940 | - * &_wpnonce=5467821 |
|
| 941 | - * and you call: |
|
| 942 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 943 | - * array( |
|
| 944 | - * 'action' => 'resend_something', |
|
| 945 | - * 'page=>espresso_registrations' |
|
| 946 | - * ), |
|
| 947 | - * $some_url, |
|
| 948 | - * true |
|
| 949 | - * ); |
|
| 950 | - * It will produce a url in this structure: |
|
| 951 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 952 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 953 | - * month_range]=March%202015 |
|
| 954 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 955 | - * @return string |
|
| 956 | - */ |
|
| 957 | - public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 958 | - { |
|
| 959 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 960 | - if ($sticky) { |
|
| 961 | - $request = $_REQUEST; |
|
| 962 | - unset($request['_wp_http_referer']); |
|
| 963 | - unset($request['wp_referer']); |
|
| 964 | - foreach ($request as $key => $value) { |
|
| 965 | - //do not add nonces |
|
| 966 | - if (strpos($key, 'nonce') !== false) { |
|
| 967 | - continue; |
|
| 968 | - } |
|
| 969 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 970 | - } |
|
| 971 | - } |
|
| 972 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * This returns a generated link that will load the related help tab. |
|
| 979 | - * |
|
| 980 | - * @param string $help_tab_id the id for the connected help tab |
|
| 981 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 982 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 983 | - * @uses EEH_Template::get_help_tab_link() |
|
| 984 | - * @return string generated link |
|
| 985 | - */ |
|
| 986 | - protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 987 | - { |
|
| 988 | - return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * _add_help_tabs |
|
| 995 | - * Note child classes define their help tabs within the page_config array. |
|
| 996 | - * |
|
| 997 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 998 | - * @access protected |
|
| 999 | - * @return void |
|
| 1000 | - */ |
|
| 1001 | - protected function _add_help_tabs() |
|
| 1002 | - { |
|
| 1003 | - $tour_buttons = ''; |
|
| 1004 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1005 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1006 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1007 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1008 | - $tb = array(); |
|
| 1009 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1010 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1011 | - //if this is the end tour then we don't need to setup a button |
|
| 1012 | - if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1013 | - continue; |
|
| 1014 | - } |
|
| 1015 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1016 | - } |
|
| 1017 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1018 | - $tour_buttons .= '</div></div>'; |
|
| 1019 | - } |
|
| 1020 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1021 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1022 | - //check that the callback given is valid |
|
| 1023 | - if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1024 | - throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1025 | - 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1026 | - } |
|
| 1027 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1028 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1029 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1030 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1031 | - } |
|
| 1032 | - //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1033 | - if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1034 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1035 | - } |
|
| 1036 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1037 | - if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1038 | - $_ht['id'] = $this->page_slug; |
|
| 1039 | - $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1040 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1041 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1042 | - }/**/ |
|
| 1043 | - if ( ! isset($config['help_tabs'])) { |
|
| 1044 | - return; |
|
| 1045 | - } //no help tabs for this route |
|
| 1046 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1047 | - //we're here so there ARE help tabs! |
|
| 1048 | - //make sure we've got what we need |
|
| 1049 | - if ( ! isset($cfg['title'])) { |
|
| 1050 | - throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1051 | - } |
|
| 1052 | - if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1053 | - throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1054 | - 'event_espresso')); |
|
| 1055 | - } |
|
| 1056 | - //first priority goes to content. |
|
| 1057 | - if ( ! empty($cfg['content'])) { |
|
| 1058 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1059 | - //second priority goes to filename |
|
| 1060 | - } else if ( ! empty($cfg['filename'])) { |
|
| 1061 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1062 | - //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1063 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1064 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1065 | - if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1066 | - EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1067 | - 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1068 | - return; |
|
| 1069 | - } |
|
| 1070 | - $template_args['admin_page_obj'] = $this; |
|
| 1071 | - $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1072 | - } else { |
|
| 1073 | - $content = ''; |
|
| 1074 | - } |
|
| 1075 | - //check if callback is valid |
|
| 1076 | - if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1077 | - EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1078 | - 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1079 | - return; |
|
| 1080 | - } |
|
| 1081 | - //setup config array for help tab method |
|
| 1082 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1083 | - $_ht = array( |
|
| 1084 | - 'id' => $id, |
|
| 1085 | - 'title' => $cfg['title'], |
|
| 1086 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1087 | - 'content' => $content, |
|
| 1088 | - ); |
|
| 1089 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1098 | - * |
|
| 1099 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1100 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1101 | - * @access protected |
|
| 1102 | - * @return void |
|
| 1103 | - */ |
|
| 1104 | - protected function _add_help_tour() |
|
| 1105 | - { |
|
| 1106 | - $tours = array(); |
|
| 1107 | - $this->_help_tour = array(); |
|
| 1108 | - //exit early if help tours are turned off globally |
|
| 1109 | - if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1110 | - return; |
|
| 1111 | - } |
|
| 1112 | - //loop through _page_config to find any help_tour defined |
|
| 1113 | - foreach ($this->_page_config as $route => $config) { |
|
| 1114 | - //we're only going to set things up for this route |
|
| 1115 | - if ($route !== $this->_req_action) { |
|
| 1116 | - continue; |
|
| 1117 | - } |
|
| 1118 | - if (isset($config['help_tour'])) { |
|
| 1119 | - foreach ($config['help_tour'] as $tour) { |
|
| 1120 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1121 | - //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1122 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1123 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1124 | - if ( ! is_readable($file_path)) { |
|
| 1125 | - EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
|
| 1126 | - $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1127 | - return; |
|
| 1128 | - } |
|
| 1129 | - require_once $file_path; |
|
| 1130 | - if ( ! class_exists($tour)) { |
|
| 1131 | - $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1132 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1133 | - 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1134 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1135 | - } |
|
| 1136 | - $a = new ReflectionClass($tour); |
|
| 1137 | - $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1138 | - $tours[] = $tour_obj; |
|
| 1139 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1140 | - } |
|
| 1141 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1142 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1143 | - $tours[] = $end_stop_tour; |
|
| 1144 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - if ( ! empty($tours)) { |
|
| 1148 | - $this->_help_tour['tours'] = $tours; |
|
| 1149 | - } |
|
| 1150 | - //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1157 | - * |
|
| 1158 | - * @access protected |
|
| 1159 | - * @return void |
|
| 1160 | - */ |
|
| 1161 | - protected function _add_qtips() |
|
| 1162 | - { |
|
| 1163 | - if (isset($this->_route_config['qtips'])) { |
|
| 1164 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1165 | - //load qtip loader |
|
| 1166 | - $path = array( |
|
| 1167 | - $this->_get_dir() . '/qtips/', |
|
| 1168 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1169 | - ); |
|
| 1170 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1171 | - } |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * _set_nav_tabs |
|
| 1178 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1179 | - * |
|
| 1180 | - * @access protected |
|
| 1181 | - * @return void |
|
| 1182 | - */ |
|
| 1183 | - protected function _set_nav_tabs() |
|
| 1184 | - { |
|
| 1185 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1186 | - $i = 0; |
|
| 1187 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1188 | - if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1189 | - continue; |
|
| 1190 | - } //no nav tab for this config |
|
| 1191 | - //check for persistent flag |
|
| 1192 | - if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1193 | - continue; |
|
| 1194 | - } //nav tab is only to appear when route requested. |
|
| 1195 | - if ( ! $this->check_user_access($slug, true)) { |
|
| 1196 | - continue; |
|
| 1197 | - } //no nav tab becasue current user does not have access. |
|
| 1198 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1199 | - $this->_nav_tabs[$slug] = array( |
|
| 1200 | - 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1201 | - 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1202 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1203 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1204 | - ); |
|
| 1205 | - $i++; |
|
| 1206 | - } |
|
| 1207 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1208 | - if (empty($this->_nav_tabs)) { |
|
| 1209 | - $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1210 | - 'url' => $this->admin_base_url, |
|
| 1211 | - 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1212 | - 'css_class' => 'nav-tab-active', |
|
| 1213 | - 'order' => 10, |
|
| 1214 | - ); |
|
| 1215 | - } |
|
| 1216 | - //now let's sort the tabs according to order |
|
| 1217 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * _set_current_labels |
|
| 1224 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1225 | - * |
|
| 1226 | - * @access private |
|
| 1227 | - * @return void |
|
| 1228 | - */ |
|
| 1229 | - private function _set_current_labels() |
|
| 1230 | - { |
|
| 1231 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1232 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1233 | - if (is_array($text)) { |
|
| 1234 | - foreach ($text as $sublabel => $subtext) { |
|
| 1235 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1236 | - } |
|
| 1237 | - } else { |
|
| 1238 | - $this->_labels[$label] = $text; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * verifies user access for this admin page |
|
| 1248 | - * |
|
| 1249 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1250 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1251 | - * @return BOOL|wp_die() |
|
| 1252 | - */ |
|
| 1253 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1254 | - { |
|
| 1255 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1256 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1257 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1258 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1259 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1260 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1261 | - } else { |
|
| 1262 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1263 | - } |
|
| 1264 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1265 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1266 | - if ($verify_only) { |
|
| 1267 | - return false; |
|
| 1268 | - } else { |
|
| 1269 | - if ( is_user_logged_in() ) { |
|
| 1270 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1271 | - } else { |
|
| 1272 | - return false; |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - return true; |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * admin_init_global |
|
| 1283 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1284 | - * This method executes for ALL EE Admin pages. |
|
| 1285 | - * |
|
| 1286 | - * @access public |
|
| 1287 | - * @return void |
|
| 1288 | - */ |
|
| 1289 | - public function admin_init_global() |
|
| 1290 | - { |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * wp_loaded_global |
|
| 1297 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1298 | - * |
|
| 1299 | - * @access public |
|
| 1300 | - * @return void |
|
| 1301 | - */ |
|
| 1302 | - public function wp_loaded() |
|
| 1303 | - { |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - /** |
|
| 1309 | - * admin_notices |
|
| 1310 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1311 | - * |
|
| 1312 | - * @access public |
|
| 1313 | - * @return void |
|
| 1314 | - */ |
|
| 1315 | - public function admin_notices_global() |
|
| 1316 | - { |
|
| 1317 | - $this->_display_no_javascript_warning(); |
|
| 1318 | - $this->_display_espresso_notices(); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - public function network_admin_notices_global() |
|
| 1324 | - { |
|
| 1325 | - $this->_display_no_javascript_warning(); |
|
| 1326 | - $this->_display_espresso_notices(); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * admin_footer_scripts_global |
|
| 1333 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1334 | - * |
|
| 1335 | - * @access public |
|
| 1336 | - * @return void |
|
| 1337 | - */ |
|
| 1338 | - public function admin_footer_scripts_global() |
|
| 1339 | - { |
|
| 1340 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1341 | - $this->_add_admin_page_overlay(); |
|
| 1342 | - //if metaboxes are present we need to add the nonce field |
|
| 1343 | - if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1344 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1345 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1346 | - } |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * admin_footer_global |
|
| 1353 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1354 | - * |
|
| 1355 | - * @access public |
|
| 1356 | - * @return void |
|
| 1357 | - */ |
|
| 1358 | - public function admin_footer_global() |
|
| 1359 | - { |
|
| 1360 | - //dialog container for dialog helper |
|
| 1361 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1362 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1363 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1364 | - $d_cont .= '</div>'; |
|
| 1365 | - echo $d_cont; |
|
| 1366 | - //help tour stuff? |
|
| 1367 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1368 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1369 | - } |
|
| 1370 | - //current set timezone for timezone js |
|
| 1371 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1378 | - * For child classes: |
|
| 1379 | - * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1380 | - * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1381 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1382 | - * 'help_trigger_id' => array( |
|
| 1383 | - * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1384 | - * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1385 | - * ) |
|
| 1386 | - * ); |
|
| 1387 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1388 | - * |
|
| 1389 | - * @access protected |
|
| 1390 | - * @return string content |
|
| 1391 | - */ |
|
| 1392 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1393 | - { |
|
| 1394 | - $content = ''; |
|
| 1395 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1396 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1397 | - //loop through the array and setup content |
|
| 1398 | - foreach ($help_array as $trigger => $help) { |
|
| 1399 | - //make sure the array is setup properly |
|
| 1400 | - if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1401 | - throw new EE_Error(__('Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1402 | - 'event_espresso')); |
|
| 1403 | - } |
|
| 1404 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1405 | - $template_args = array( |
|
| 1406 | - 'help_popup_id' => $trigger, |
|
| 1407 | - 'help_popup_title' => $help['title'], |
|
| 1408 | - 'help_popup_content' => $help['content'], |
|
| 1409 | - ); |
|
| 1410 | - $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1411 | - } |
|
| 1412 | - if ($display) { |
|
| 1413 | - echo $content; |
|
| 1414 | - } else { |
|
| 1415 | - return $content; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1423 | - * |
|
| 1424 | - * @access private |
|
| 1425 | - * @return array properly formatted array for help popup content |
|
| 1426 | - */ |
|
| 1427 | - private function _get_help_content() |
|
| 1428 | - { |
|
| 1429 | - //what is the method we're looking for? |
|
| 1430 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1431 | - //if method doesn't exist let's get out. |
|
| 1432 | - if ( ! method_exists($this, $method_name)) { |
|
| 1433 | - return array(); |
|
| 1434 | - } |
|
| 1435 | - //k we're good to go let's retrieve the help array |
|
| 1436 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1437 | - //make sure we've got an array! |
|
| 1438 | - if ( ! is_array($help_array)) { |
|
| 1439 | - throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1440 | - } |
|
| 1441 | - return $help_array; |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1448 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1449 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1450 | - * |
|
| 1451 | - * @access protected |
|
| 1452 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1453 | - * @param boolean $display if false then we return the trigger string |
|
| 1454 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1455 | - * @return string |
|
| 1456 | - */ |
|
| 1457 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1458 | - { |
|
| 1459 | - if (defined('DOING_AJAX')) { |
|
| 1460 | - return; |
|
| 1461 | - } |
|
| 1462 | - //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1463 | - $help_array = $this->_get_help_content(); |
|
| 1464 | - $help_content = ''; |
|
| 1465 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1466 | - $help_array[$trigger_id] = array( |
|
| 1467 | - 'title' => __('Missing Content', 'event_espresso'), |
|
| 1468 | - 'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1469 | - 'event_espresso'), |
|
| 1470 | - ); |
|
| 1471 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1472 | - } |
|
| 1473 | - //let's setup the trigger |
|
| 1474 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1475 | - $content = $content . $help_content; |
|
| 1476 | - if ($display) { |
|
| 1477 | - echo $content; |
|
| 1478 | - } else { |
|
| 1479 | - return $content; |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * _add_global_screen_options |
|
| 1487 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1488 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1489 | - * |
|
| 1490 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1491 | - * see also WP_Screen object documents... |
|
| 1492 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1493 | - * @abstract |
|
| 1494 | - * @access private |
|
| 1495 | - * @return void |
|
| 1496 | - */ |
|
| 1497 | - private function _add_global_screen_options() |
|
| 1498 | - { |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * _add_global_feature_pointers |
|
| 1505 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1506 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1507 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1508 | - * |
|
| 1509 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1510 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1511 | - * @abstract |
|
| 1512 | - * @access protected |
|
| 1513 | - * @return void |
|
| 1514 | - */ |
|
| 1515 | - private function _add_global_feature_pointers() |
|
| 1516 | - { |
|
| 1517 | - } |
|
| 1518 | - |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - /** |
|
| 1522 | - * load_global_scripts_styles |
|
| 1523 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1524 | - * |
|
| 1525 | - * @return void |
|
| 1526 | - */ |
|
| 1527 | - public function load_global_scripts_styles() |
|
| 1528 | - { |
|
| 1529 | - /** STYLES **/ |
|
| 1530 | - // add debugging styles |
|
| 1531 | - if (WP_DEBUG) { |
|
| 1532 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1533 | - } |
|
| 1534 | - //register all styles |
|
| 1535 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1536 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | - //helpers styles |
|
| 1538 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1539 | - //enqueue global styles |
|
| 1540 | - wp_enqueue_style('ee-admin-css'); |
|
| 1541 | - /** SCRIPTS **/ |
|
| 1542 | - //register all scripts |
|
| 1543 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1546 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | - // register jQuery Validate - see /includes/functions/wp_hooks.php |
|
| 1548 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 1549 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1550 | - //script for sorting tables |
|
| 1551 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | - //script for parsing uri's |
|
| 1553 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | - //and parsing associative serialized form elements |
|
| 1555 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | - //helpers scripts |
|
| 1557 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1558 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1559 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1560 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1561 | - //google charts |
|
| 1562 | - wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1563 | - //enqueue global scripts |
|
| 1564 | - //taking care of metaboxes |
|
| 1565 | - if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) { |
|
| 1566 | - wp_enqueue_script('dashboard'); |
|
| 1567 | - } |
|
| 1568 | - //enqueue thickbox for ee help popups. default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups |
|
| 1569 | - if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) { |
|
| 1570 | - wp_enqueue_script('ee_admin_js'); |
|
| 1571 | - wp_enqueue_style('ee-admin-css'); |
|
| 1572 | - } |
|
| 1573 | - //localize script for ajax lazy loading |
|
| 1574 | - $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1575 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1576 | - /** |
|
| 1577 | - * help tour stuff |
|
| 1578 | - */ |
|
| 1579 | - if ( ! empty($this->_help_tour)) { |
|
| 1580 | - //register the js for kicking things off |
|
| 1581 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1582 | - //setup tours for the js tour object |
|
| 1583 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1584 | - $tours[] = array( |
|
| 1585 | - 'id' => $tour->get_slug(), |
|
| 1586 | - 'options' => $tour->get_options(), |
|
| 1587 | - ); |
|
| 1588 | - } |
|
| 1589 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1590 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1591 | - } |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1598 | - * |
|
| 1599 | - * @access public |
|
| 1600 | - * @return void |
|
| 1601 | - */ |
|
| 1602 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1603 | - { |
|
| 1604 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1605 | - EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso'); |
|
| 1606 | - EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1607 | - EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1608 | - EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1609 | - EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1610 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1611 | - EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1612 | - EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1613 | - EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1614 | - EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1615 | - EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1616 | - EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1617 | - EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1618 | - EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1619 | - EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1620 | - EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1621 | - EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1622 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1623 | - EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1624 | - EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1625 | - EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1626 | - EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1627 | - EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1628 | - EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1629 | - EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1630 | - EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1631 | - EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1632 | - EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1633 | - EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1634 | - EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1635 | - EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1636 | - EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1637 | - EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1638 | - EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1639 | - EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1640 | - EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1641 | - EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1642 | - EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1643 | - EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1644 | - //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance |
|
| 1645 | - //admin page when in maintenance mode and ee_admin_js is not loaded then. This works everywhere else because |
|
| 1646 | - //espresso_core is listed as a dependency of ee_admin_js. |
|
| 1647 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - /** |
|
| 1653 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1654 | - * |
|
| 1655 | - * @access public |
|
| 1656 | - * @return void |
|
| 1657 | - */ |
|
| 1658 | - public function add_xdebug_style() |
|
| 1659 | - { |
|
| 1660 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - |
|
| 1664 | - /************************/ |
|
| 1665 | - /** LIST TABLE METHODS **/ |
|
| 1666 | - /************************/ |
|
| 1667 | - /** |
|
| 1668 | - * this sets up the list table if the current view requires it. |
|
| 1669 | - * |
|
| 1670 | - * @access protected |
|
| 1671 | - * @return void |
|
| 1672 | - */ |
|
| 1673 | - protected function _set_list_table() |
|
| 1674 | - { |
|
| 1675 | - //first is this a list_table view? |
|
| 1676 | - if ( ! isset($this->_route_config['list_table'])) { |
|
| 1677 | - return; |
|
| 1678 | - } //not a list_table view so get out. |
|
| 1679 | - //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1680 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1681 | - //user error msg |
|
| 1682 | - $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1683 | - //developer error msg |
|
| 1684 | - $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1685 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1686 | - throw new EE_Error($error_msg); |
|
| 1687 | - } |
|
| 1688 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1689 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1690 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1691 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1692 | - $this->_set_list_table_view(); |
|
| 1693 | - $this->_set_list_table_object(); |
|
| 1694 | - } |
|
| 1695 | - |
|
| 1696 | - |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * set current view for List Table |
|
| 1700 | - * |
|
| 1701 | - * @access public |
|
| 1702 | - * @return array |
|
| 1703 | - */ |
|
| 1704 | - protected function _set_list_table_view() |
|
| 1705 | - { |
|
| 1706 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1707 | - // looking at active items or dumpster diving ? |
|
| 1708 | - if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1709 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1710 | - } else { |
|
| 1711 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1712 | - } |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - |
|
| 1716 | - |
|
| 1717 | - /** |
|
| 1718 | - * _set_list_table_object |
|
| 1719 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1720 | - * |
|
| 1721 | - * @throws \EE_Error |
|
| 1722 | - */ |
|
| 1723 | - protected function _set_list_table_object() |
|
| 1724 | - { |
|
| 1725 | - if (isset($this->_route_config['list_table'])) { |
|
| 1726 | - if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1727 | - throw new EE_Error( |
|
| 1728 | - sprintf( |
|
| 1729 | - __( |
|
| 1730 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 1731 | - 'event_espresso' |
|
| 1732 | - ), |
|
| 1733 | - $this->_route_config['list_table'], |
|
| 1734 | - get_class($this) |
|
| 1735 | - ) |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - $list_table = $this->_route_config['list_table']; |
|
| 1739 | - $this->_list_table_object = new $list_table($this); |
|
| 1740 | - } |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - |
|
| 1745 | - /** |
|
| 1746 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1747 | - * |
|
| 1748 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1749 | - * urls. The array should be indexed by the view it is being |
|
| 1750 | - * added to. |
|
| 1751 | - * @return array |
|
| 1752 | - */ |
|
| 1753 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1754 | - { |
|
| 1755 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1756 | - if (empty($this->_views)) { |
|
| 1757 | - $this->_views = array(); |
|
| 1758 | - } |
|
| 1759 | - // cycle thru views |
|
| 1760 | - foreach ($this->_views as $key => $view) { |
|
| 1761 | - $query_args = array(); |
|
| 1762 | - // check for current view |
|
| 1763 | - $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1764 | - $query_args['action'] = $this->_req_action; |
|
| 1765 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1766 | - $query_args['status'] = $view['slug']; |
|
| 1767 | - //merge any other arguments sent in. |
|
| 1768 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 1769 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1770 | - } |
|
| 1771 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1772 | - } |
|
| 1773 | - return $this->_views; |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - |
|
| 1777 | - |
|
| 1778 | - /** |
|
| 1779 | - * _entries_per_page_dropdown |
|
| 1780 | - * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1781 | - * |
|
| 1782 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1783 | - * @access protected |
|
| 1784 | - * @param int $max_entries total number of rows in the table |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1788 | - { |
|
| 1789 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1790 | - $values = array(10, 25, 50, 100); |
|
| 1791 | - $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1792 | - if ($max_entries) { |
|
| 1793 | - $values[] = $max_entries; |
|
| 1794 | - sort($values); |
|
| 1795 | - } |
|
| 1796 | - $entries_per_page_dropdown = ' |
|
| 143 | + // yes / no array for admin form fields |
|
| 144 | + protected $_yes_no_values = array(); |
|
| 145 | + |
|
| 146 | + //some default things shared by all child classes |
|
| 147 | + protected $_default_espresso_metaboxes; |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * EE_Registry Object |
|
| 151 | + * |
|
| 152 | + * @var EE_Registry |
|
| 153 | + * @access protected |
|
| 154 | + */ |
|
| 155 | + protected $EE = null; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | + * |
|
| 162 | + * @var boolean |
|
| 163 | + */ |
|
| 164 | + protected $_is_caf = false; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @Constructor |
|
| 170 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | + * @access public |
|
| 172 | + */ |
|
| 173 | + public function __construct($routing = true) |
|
| 174 | + { |
|
| 175 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | + $this->_is_caf = true; |
|
| 177 | + } |
|
| 178 | + $this->_yes_no_values = array( |
|
| 179 | + array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | + array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | + ); |
|
| 182 | + //set the _req_data property. |
|
| 183 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | + //routing enabled? |
|
| 185 | + $this->_routing = $routing; |
|
| 186 | + //set initial page props (child method) |
|
| 187 | + $this->_init_page_props(); |
|
| 188 | + //set global defaults |
|
| 189 | + $this->_set_defaults(); |
|
| 190 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | + $this->_global_ajax_hooks(); |
|
| 192 | + $this->_ajax_hooks(); |
|
| 193 | + //other_page_hooks have to be early too. |
|
| 194 | + $this->_do_other_page_hooks(); |
|
| 195 | + //This just allows us to have extending clases do something specific before the parent constructor runs _page_setup. |
|
| 196 | + if (method_exists($this, '_before_page_setup')) { |
|
| 197 | + $this->_before_page_setup(); |
|
| 198 | + } |
|
| 199 | + //set up page dependencies |
|
| 200 | + $this->_page_setup(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * _init_page_props |
|
| 207 | + * Child classes use to set at least the following properties: |
|
| 208 | + * $page_slug. |
|
| 209 | + * $page_label. |
|
| 210 | + * |
|
| 211 | + * @abstract |
|
| 212 | + * @access protected |
|
| 213 | + * @return void |
|
| 214 | + */ |
|
| 215 | + abstract protected function _init_page_props(); |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * _ajax_hooks |
|
| 221 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 222 | + * Note: within the ajax callback methods. |
|
| 223 | + * |
|
| 224 | + * @abstract |
|
| 225 | + * @access protected |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + abstract protected function _ajax_hooks(); |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _define_page_props |
|
| 234 | + * child classes define page properties in here. Must include at least: |
|
| 235 | + * $_admin_base_url = base_url for all admin pages |
|
| 236 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 237 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 238 | + * array( |
|
| 239 | + * 'buttons' => array( |
|
| 240 | + * 'add' => __('label for add new button'), |
|
| 241 | + * 'edit' => __('label for edit button'), |
|
| 242 | + * 'delete' => __('label for delete button') |
|
| 243 | + * ) |
|
| 244 | + * ) |
|
| 245 | + * |
|
| 246 | + * @abstract |
|
| 247 | + * @access protected |
|
| 248 | + * @return void |
|
| 249 | + */ |
|
| 250 | + abstract protected function _define_page_props(); |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * _set_page_routes |
|
| 256 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 257 | + * route. Here's the format |
|
| 258 | + * $this->_page_routes = array( |
|
| 259 | + * 'default' => array( |
|
| 260 | + * 'func' => '_default_method_handling_route', |
|
| 261 | + * 'args' => array('array','of','args'), |
|
| 262 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 263 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 264 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 265 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 266 | + * ), |
|
| 267 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 268 | + * ) |
|
| 269 | + * ) |
|
| 270 | + * |
|
| 271 | + * @abstract |
|
| 272 | + * @access protected |
|
| 273 | + * @return void |
|
| 274 | + */ |
|
| 275 | + abstract protected function _set_page_routes(); |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * _set_page_config |
|
| 281 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 282 | + * Format: |
|
| 283 | + * $this->_page_config = array( |
|
| 284 | + * 'default' => array( |
|
| 285 | + * 'labels' => array( |
|
| 286 | + * 'buttons' => array( |
|
| 287 | + * 'add' => __('label for adding item'), |
|
| 288 | + * 'edit' => __('label for editing item'), |
|
| 289 | + * 'delete' => __('label for deleting item') |
|
| 290 | + * ), |
|
| 291 | + * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 292 | + * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 293 | + * 'nav' => array( |
|
| 294 | + * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 295 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 296 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 297 | + * 'order' => 10, //required to indicate tab position. |
|
| 298 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 299 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 300 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 301 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 302 | + * this flag to make sure the necessary js gets enqueued on page load. |
|
| 303 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 304 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 305 | + * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 306 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 307 | + * 'tab_id' => array( |
|
| 308 | + * 'title' => 'tab_title', |
|
| 309 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 310 | + * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 311 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 312 | + * ), |
|
| 313 | + * 'tab2_id' => array( |
|
| 314 | + * 'title' => 'tab2 title', |
|
| 315 | + * 'filename' => 'file_name_2' |
|
| 316 | + * 'callback' => 'callback_method_for_content', |
|
| 317 | + * ), |
|
| 318 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 319 | + * 'help_tour' => array( |
|
| 320 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 321 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 322 | + * ), |
|
| 323 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 324 | + * 'require_nonce' to FALSE |
|
| 325 | + * ) |
|
| 326 | + * ) |
|
| 327 | + * |
|
| 328 | + * @abstract |
|
| 329 | + * @access protected |
|
| 330 | + * @return void |
|
| 331 | + */ |
|
| 332 | + abstract protected function _set_page_config(); |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** end sample help_tour methods **/ |
|
| 339 | + /** |
|
| 340 | + * _add_screen_options |
|
| 341 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 342 | + * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 343 | + * |
|
| 344 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 345 | + * see also WP_Screen object documents... |
|
| 346 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 347 | + * @abstract |
|
| 348 | + * @access protected |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + abstract protected function _add_screen_options(); |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * _add_feature_pointers |
|
| 357 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 358 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 359 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 360 | + * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 361 | + * |
|
| 362 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 363 | + * @abstract |
|
| 364 | + * @access protected |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + abstract protected function _add_feature_pointers(); |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * load_scripts_styles |
|
| 373 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 374 | + * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 375 | + * |
|
| 376 | + * @abstract |
|
| 377 | + * @access public |
|
| 378 | + * @return void |
|
| 379 | + */ |
|
| 380 | + abstract public function load_scripts_styles(); |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * admin_init |
|
| 386 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 387 | + * |
|
| 388 | + * @abstract |
|
| 389 | + * @access public |
|
| 390 | + * @return void |
|
| 391 | + */ |
|
| 392 | + abstract public function admin_init(); |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * admin_notices |
|
| 398 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 399 | + * |
|
| 400 | + * @abstract |
|
| 401 | + * @access public |
|
| 402 | + * @return void |
|
| 403 | + */ |
|
| 404 | + abstract public function admin_notices(); |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * admin_footer_scripts |
|
| 410 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 411 | + * |
|
| 412 | + * @access public |
|
| 413 | + * @return void |
|
| 414 | + */ |
|
| 415 | + abstract public function admin_footer_scripts(); |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * admin_footer |
|
| 421 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 422 | + * |
|
| 423 | + * @access public |
|
| 424 | + * @return void |
|
| 425 | + */ |
|
| 426 | + public function admin_footer() |
|
| 427 | + { |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * _global_ajax_hooks |
|
| 434 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 435 | + * Note: within the ajax callback methods. |
|
| 436 | + * |
|
| 437 | + * @abstract |
|
| 438 | + * @access protected |
|
| 439 | + * @return void |
|
| 440 | + */ |
|
| 441 | + protected function _global_ajax_hooks() |
|
| 442 | + { |
|
| 443 | + //for lazy loading of metabox content |
|
| 444 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + public function ajax_metabox_content() |
|
| 450 | + { |
|
| 451 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 452 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 453 | + self::cached_rss_display($contentid, $url); |
|
| 454 | + wp_die(); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * _page_setup |
|
| 461 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 462 | + * |
|
| 463 | + * @final |
|
| 464 | + * @access protected |
|
| 465 | + * @return void |
|
| 466 | + */ |
|
| 467 | + final protected function _page_setup() |
|
| 468 | + { |
|
| 469 | + //requires? |
|
| 470 | + //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 471 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 472 | + //next verify if we need to load anything... |
|
| 473 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 474 | + $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 475 | + global $ee_menu_slugs; |
|
| 476 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 477 | + if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 478 | + return false; |
|
| 479 | + } |
|
| 480 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 481 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 482 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 483 | + } |
|
| 484 | + // then set blank or -1 action values to 'default' |
|
| 485 | + $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 486 | + //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 487 | + $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 488 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 489 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 490 | + $this->_current_view = $this->_req_action; |
|
| 491 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 492 | + $this->_define_page_props(); |
|
| 493 | + $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 494 | + //default things |
|
| 495 | + $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 496 | + //set page configs |
|
| 497 | + $this->_set_page_routes(); |
|
| 498 | + $this->_set_page_config(); |
|
| 499 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 500 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 501 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 502 | + } |
|
| 503 | + //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 504 | + if (method_exists($this, '_extend_page_config')) { |
|
| 505 | + $this->_extend_page_config(); |
|
| 506 | + } |
|
| 507 | + //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 508 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 509 | + $this->_extend_page_config_for_cpt(); |
|
| 510 | + } |
|
| 511 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 512 | + $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | + $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 515 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 517 | + } |
|
| 518 | + //next route only if routing enabled |
|
| 519 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 520 | + $this->_verify_routes(); |
|
| 521 | + //next let's just check user_access and kill if no access |
|
| 522 | + $this->check_user_access(); |
|
| 523 | + if ($this->_is_UI_request) { |
|
| 524 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 525 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 526 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 528 | + } |
|
| 529 | + } else { |
|
| 530 | + //hijack regular WP loading and route admin request immediately |
|
| 531 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 532 | + $this->route_admin_request(); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 541 | + * |
|
| 542 | + * @access private |
|
| 543 | + * @return void |
|
| 544 | + */ |
|
| 545 | + private function _do_other_page_hooks() |
|
| 546 | + { |
|
| 547 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 548 | + foreach ($registered_pages as $page) { |
|
| 549 | + //now let's setup the file name and class that should be present |
|
| 550 | + $classname = str_replace('.class.php', '', $page); |
|
| 551 | + //autoloaders should take care of loading file |
|
| 552 | + if ( ! class_exists($classname)) { |
|
| 553 | + $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | + $error_msg[] = $error_msg[0] |
|
| 555 | + . "\r\n" |
|
| 556 | + . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | + 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 558 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 559 | + } |
|
| 560 | + $a = new ReflectionClass($classname); |
|
| 561 | + //notice we are passing the instance of this class to the hook object. |
|
| 562 | + $hookobj[] = $a->newInstance($this); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + public function load_page_dependencies() |
|
| 569 | + { |
|
| 570 | + try { |
|
| 571 | + $this->_load_page_dependencies(); |
|
| 572 | + } catch (EE_Error $e) { |
|
| 573 | + $e->get_error(); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * load_page_dependencies |
|
| 581 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 582 | + * |
|
| 583 | + * @access public |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + protected function _load_page_dependencies() |
|
| 587 | + { |
|
| 588 | + //let's set the current_screen and screen options to override what WP set |
|
| 589 | + $this->_current_screen = get_current_screen(); |
|
| 590 | + //load admin_notices - global, page class, and view specific |
|
| 591 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 592 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 593 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 595 | + } |
|
| 596 | + //load network admin_notices - global, page class, and view specific |
|
| 597 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 598 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 600 | + } |
|
| 601 | + //this will save any per_page screen options if they are present |
|
| 602 | + $this->_set_per_page_screen_options(); |
|
| 603 | + //setup list table properties |
|
| 604 | + $this->_set_list_table(); |
|
| 605 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 606 | + $this->_add_registered_meta_boxes(); |
|
| 607 | + $this->_add_screen_columns(); |
|
| 608 | + //add screen options - global, page child class, and view specific |
|
| 609 | + $this->_add_global_screen_options(); |
|
| 610 | + $this->_add_screen_options(); |
|
| 611 | + if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | + call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 613 | + } |
|
| 614 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 615 | + $this->_add_help_tour(); |
|
| 616 | + $this->_add_help_tabs(); |
|
| 617 | + $this->_add_qtips(); |
|
| 618 | + //add feature_pointers - global, page child class, and view specific |
|
| 619 | + $this->_add_feature_pointers(); |
|
| 620 | + $this->_add_global_feature_pointers(); |
|
| 621 | + if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | + call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 623 | + } |
|
| 624 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 625 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 626 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 627 | + if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 629 | + } |
|
| 630 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 631 | + //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 632 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 633 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 634 | + if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 636 | + } |
|
| 637 | + //admin footer scripts |
|
| 638 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 639 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 640 | + if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | + add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 642 | + } |
|
| 643 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 644 | + //targeted hook |
|
| 645 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * _set_defaults |
|
| 652 | + * This sets some global defaults for class properties. |
|
| 653 | + */ |
|
| 654 | + private function _set_defaults() |
|
| 655 | + { |
|
| 656 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 657 | + $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 658 | + $this->default_nav_tab_name = 'overview'; |
|
| 659 | + //init template args |
|
| 660 | + $this->_template_args = array( |
|
| 661 | + 'admin_page_header' => '', |
|
| 662 | + 'admin_page_content' => '', |
|
| 663 | + 'post_body_content' => '', |
|
| 664 | + 'before_list_table' => '', |
|
| 665 | + 'after_list_table' => '', |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * route_admin_request |
|
| 673 | + * |
|
| 674 | + * @see _route_admin_request() |
|
| 675 | + * @access public |
|
| 676 | + * @return void|exception error |
|
| 677 | + */ |
|
| 678 | + public function route_admin_request() |
|
| 679 | + { |
|
| 680 | + try { |
|
| 681 | + $this->_route_admin_request(); |
|
| 682 | + } catch (EE_Error $e) { |
|
| 683 | + $e->get_error(); |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function set_wp_page_slug($wp_page_slug) |
|
| 690 | + { |
|
| 691 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 692 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 693 | + if (is_network_admin()) { |
|
| 694 | + $this->_wp_page_slug .= '-network'; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * _verify_routes |
|
| 702 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 703 | + * |
|
| 704 | + * @access protected |
|
| 705 | + * @return void |
|
| 706 | + */ |
|
| 707 | + protected function _verify_routes() |
|
| 708 | + { |
|
| 709 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 710 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 711 | + return false; |
|
| 712 | + } |
|
| 713 | + $this->_route = false; |
|
| 714 | + $func = false; |
|
| 715 | + $args = array(); |
|
| 716 | + // check that the page_routes array is not empty |
|
| 717 | + if (empty($this->_page_routes)) { |
|
| 718 | + // user error msg |
|
| 719 | + $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 720 | + // developer error msg |
|
| 721 | + $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | + throw new EE_Error($error_msg); |
|
| 723 | + } |
|
| 724 | + // and that the requested page route exists |
|
| 725 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 726 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 727 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 728 | + } else { |
|
| 729 | + // user error msg |
|
| 730 | + $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 731 | + // developer error msg |
|
| 732 | + $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | + throw new EE_Error($error_msg); |
|
| 734 | + } |
|
| 735 | + // and that a default route exists |
|
| 736 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 737 | + // user error msg |
|
| 738 | + $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 739 | + // developer error msg |
|
| 740 | + $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | + throw new EE_Error($error_msg); |
|
| 742 | + } |
|
| 743 | + //first lets' catch if the UI request has EVER been set. |
|
| 744 | + if ($this->_is_UI_request === null) { |
|
| 745 | + //lets set if this is a UI request or not. |
|
| 746 | + $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 747 | + //wait a minute... we might have a noheader in the route array |
|
| 748 | + $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 749 | + } |
|
| 750 | + $this->_set_current_labels(); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 757 | + * |
|
| 758 | + * @param string $route the route name we're verifying |
|
| 759 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 760 | + */ |
|
| 761 | + protected function _verify_route($route) |
|
| 762 | + { |
|
| 763 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 764 | + return true; |
|
| 765 | + } else { |
|
| 766 | + // user error msg |
|
| 767 | + $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 768 | + // developer error msg |
|
| 769 | + $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | + throw new EE_Error($error_msg); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * perform nonce verification |
|
| 778 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 779 | + * |
|
| 780 | + * @param string $nonce The nonce sent |
|
| 781 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 782 | + * @return mixed (bool|die) |
|
| 783 | + */ |
|
| 784 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 785 | + { |
|
| 786 | + // verify nonce against expected value |
|
| 787 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 788 | + // these are not the droids you are looking for !!! |
|
| 789 | + $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 790 | + if (WP_DEBUG) { |
|
| 791 | + $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | + } |
|
| 793 | + if ( ! defined('DOING_AJAX')) { |
|
| 794 | + wp_die($msg); |
|
| 795 | + } else { |
|
| 796 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | + $this->_return_json(); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + /** |
|
| 805 | + * _route_admin_request() |
|
| 806 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 807 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 808 | + * in the page routes and then will try to load the corresponding method. |
|
| 809 | + * |
|
| 810 | + * @access protected |
|
| 811 | + * @return void |
|
| 812 | + * @throws \EE_Error |
|
| 813 | + */ |
|
| 814 | + protected function _route_admin_request() |
|
| 815 | + { |
|
| 816 | + if ( ! $this->_is_UI_request) { |
|
| 817 | + $this->_verify_routes(); |
|
| 818 | + } |
|
| 819 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 820 | + ? $this->_route_config['require_nonce'] |
|
| 821 | + : true; |
|
| 822 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 823 | + // set nonce from post data |
|
| 824 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 825 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 826 | + : ''; |
|
| 827 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 828 | + } |
|
| 829 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 830 | + if ($this->_is_UI_request) { |
|
| 831 | + $this->_set_nav_tabs(); |
|
| 832 | + } |
|
| 833 | + // grab callback function |
|
| 834 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 835 | + // check if callback has args |
|
| 836 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 837 | + $error_msg = ''; |
|
| 838 | + // action right before calling route |
|
| 839 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 840 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 841 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 842 | + } |
|
| 843 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 844 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 845 | + $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 846 | + if ( ! empty($func)) { |
|
| 847 | + if (is_array($func)) { |
|
| 848 | + list($class, $method) = $func; |
|
| 849 | + } else if (strpos($func, '::') !== false) { |
|
| 850 | + list($class, $method) = explode('::', $func); |
|
| 851 | + } else { |
|
| 852 | + $class = $this; |
|
| 853 | + $method = $func; |
|
| 854 | + } |
|
| 855 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 856 | + // send along this admin page object for access by addons. |
|
| 857 | + $args['admin_page_object'] = $this; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + if ( |
|
| 861 | + //is it a method on a class that doesn't work? |
|
| 862 | + ( |
|
| 863 | + ( |
|
| 864 | + method_exists($class, $method) |
|
| 865 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 866 | + ) |
|
| 867 | + && ( |
|
| 868 | + //is it a standalone function that doesn't work? |
|
| 869 | + function_exists($method) |
|
| 870 | + && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 871 | + ) |
|
| 872 | + ) |
|
| 873 | + || ( |
|
| 874 | + //is it neither a class method NOR a standalone function? |
|
| 875 | + ! method_exists($class, $method) |
|
| 876 | + && ! function_exists($method) |
|
| 877 | + ) |
|
| 878 | + ) { |
|
| 879 | + // user error msg |
|
| 880 | + $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 881 | + // developer error msg |
|
| 882 | + $error_msg .= '||'; |
|
| 883 | + $error_msg .= sprintf( |
|
| 884 | + __( |
|
| 885 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 886 | + 'event_espresso' |
|
| 887 | + ), |
|
| 888 | + $method |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + if ( ! empty($error_msg)) { |
|
| 892 | + throw new EE_Error($error_msg); |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 896 | + //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 897 | + if ($this->_is_UI_request === false |
|
| 898 | + && is_array($this->_route) |
|
| 899 | + && ! empty($this->_route['headers_sent_route']) |
|
| 900 | + ) { |
|
| 901 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 909 | + * route redirects to a headers route in its route config. |
|
| 910 | + * |
|
| 911 | + * @since 4.3.0 |
|
| 912 | + * @param string $new_route New (non header) route to redirect to. |
|
| 913 | + * @return void |
|
| 914 | + */ |
|
| 915 | + protected function _reset_routing_properties($new_route) |
|
| 916 | + { |
|
| 917 | + $this->_is_UI_request = true; |
|
| 918 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 919 | + $this->_req_data['action'] = $new_route; |
|
| 920 | + //rerun page setup |
|
| 921 | + $this->_page_setup(); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * _add_query_arg |
|
| 928 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 929 | + *(internally just uses EEH_URL's function with the same name) |
|
| 930 | + * |
|
| 931 | + * @access public |
|
| 932 | + * @param array $args |
|
| 933 | + * @param string $url |
|
| 934 | + * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 935 | + * url in an associative array indexed by the key 'wp_referer'; |
|
| 936 | + * Example usage: |
|
| 937 | + * If the current page is: |
|
| 938 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 939 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 940 | + * &_wpnonce=5467821 |
|
| 941 | + * and you call: |
|
| 942 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 943 | + * array( |
|
| 944 | + * 'action' => 'resend_something', |
|
| 945 | + * 'page=>espresso_registrations' |
|
| 946 | + * ), |
|
| 947 | + * $some_url, |
|
| 948 | + * true |
|
| 949 | + * ); |
|
| 950 | + * It will produce a url in this structure: |
|
| 951 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 952 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 953 | + * month_range]=March%202015 |
|
| 954 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 955 | + * @return string |
|
| 956 | + */ |
|
| 957 | + public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 958 | + { |
|
| 959 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 960 | + if ($sticky) { |
|
| 961 | + $request = $_REQUEST; |
|
| 962 | + unset($request['_wp_http_referer']); |
|
| 963 | + unset($request['wp_referer']); |
|
| 964 | + foreach ($request as $key => $value) { |
|
| 965 | + //do not add nonces |
|
| 966 | + if (strpos($key, 'nonce') !== false) { |
|
| 967 | + continue; |
|
| 968 | + } |
|
| 969 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 970 | + } |
|
| 971 | + } |
|
| 972 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * This returns a generated link that will load the related help tab. |
|
| 979 | + * |
|
| 980 | + * @param string $help_tab_id the id for the connected help tab |
|
| 981 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 982 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 983 | + * @uses EEH_Template::get_help_tab_link() |
|
| 984 | + * @return string generated link |
|
| 985 | + */ |
|
| 986 | + protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 987 | + { |
|
| 988 | + return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * _add_help_tabs |
|
| 995 | + * Note child classes define their help tabs within the page_config array. |
|
| 996 | + * |
|
| 997 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 998 | + * @access protected |
|
| 999 | + * @return void |
|
| 1000 | + */ |
|
| 1001 | + protected function _add_help_tabs() |
|
| 1002 | + { |
|
| 1003 | + $tour_buttons = ''; |
|
| 1004 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1005 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1006 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1007 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1008 | + $tb = array(); |
|
| 1009 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1010 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1011 | + //if this is the end tour then we don't need to setup a button |
|
| 1012 | + if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1013 | + continue; |
|
| 1014 | + } |
|
| 1015 | + $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1016 | + } |
|
| 1017 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1018 | + $tour_buttons .= '</div></div>'; |
|
| 1019 | + } |
|
| 1020 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1021 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1022 | + //check that the callback given is valid |
|
| 1023 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1024 | + throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1025 | + 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1026 | + } |
|
| 1027 | + $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1028 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1029 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1030 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1031 | + } |
|
| 1032 | + //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1033 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1034 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1035 | + } |
|
| 1036 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1037 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1038 | + $_ht['id'] = $this->page_slug; |
|
| 1039 | + $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1040 | + $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1041 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1042 | + }/**/ |
|
| 1043 | + if ( ! isset($config['help_tabs'])) { |
|
| 1044 | + return; |
|
| 1045 | + } //no help tabs for this route |
|
| 1046 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1047 | + //we're here so there ARE help tabs! |
|
| 1048 | + //make sure we've got what we need |
|
| 1049 | + if ( ! isset($cfg['title'])) { |
|
| 1050 | + throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1051 | + } |
|
| 1052 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1053 | + throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1054 | + 'event_espresso')); |
|
| 1055 | + } |
|
| 1056 | + //first priority goes to content. |
|
| 1057 | + if ( ! empty($cfg['content'])) { |
|
| 1058 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1059 | + //second priority goes to filename |
|
| 1060 | + } else if ( ! empty($cfg['filename'])) { |
|
| 1061 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1062 | + //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1063 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1064 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1065 | + if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1066 | + EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1067 | + 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1068 | + return; |
|
| 1069 | + } |
|
| 1070 | + $template_args['admin_page_obj'] = $this; |
|
| 1071 | + $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1072 | + } else { |
|
| 1073 | + $content = ''; |
|
| 1074 | + } |
|
| 1075 | + //check if callback is valid |
|
| 1076 | + if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1077 | + EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1078 | + 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1079 | + return; |
|
| 1080 | + } |
|
| 1081 | + //setup config array for help tab method |
|
| 1082 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1083 | + $_ht = array( |
|
| 1084 | + 'id' => $id, |
|
| 1085 | + 'title' => $cfg['title'], |
|
| 1086 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1087 | + 'content' => $content, |
|
| 1088 | + ); |
|
| 1089 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1090 | + } |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1098 | + * |
|
| 1099 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1100 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1101 | + * @access protected |
|
| 1102 | + * @return void |
|
| 1103 | + */ |
|
| 1104 | + protected function _add_help_tour() |
|
| 1105 | + { |
|
| 1106 | + $tours = array(); |
|
| 1107 | + $this->_help_tour = array(); |
|
| 1108 | + //exit early if help tours are turned off globally |
|
| 1109 | + if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1110 | + return; |
|
| 1111 | + } |
|
| 1112 | + //loop through _page_config to find any help_tour defined |
|
| 1113 | + foreach ($this->_page_config as $route => $config) { |
|
| 1114 | + //we're only going to set things up for this route |
|
| 1115 | + if ($route !== $this->_req_action) { |
|
| 1116 | + continue; |
|
| 1117 | + } |
|
| 1118 | + if (isset($config['help_tour'])) { |
|
| 1119 | + foreach ($config['help_tour'] as $tour) { |
|
| 1120 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1121 | + //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1122 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1123 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1124 | + if ( ! is_readable($file_path)) { |
|
| 1125 | + EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
|
| 1126 | + $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1127 | + return; |
|
| 1128 | + } |
|
| 1129 | + require_once $file_path; |
|
| 1130 | + if ( ! class_exists($tour)) { |
|
| 1131 | + $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1132 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1133 | + 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1134 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1135 | + } |
|
| 1136 | + $a = new ReflectionClass($tour); |
|
| 1137 | + $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1138 | + $tours[] = $tour_obj; |
|
| 1139 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1140 | + } |
|
| 1141 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1142 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1143 | + $tours[] = $end_stop_tour; |
|
| 1144 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + if ( ! empty($tours)) { |
|
| 1148 | + $this->_help_tour['tours'] = $tours; |
|
| 1149 | + } |
|
| 1150 | + //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1157 | + * |
|
| 1158 | + * @access protected |
|
| 1159 | + * @return void |
|
| 1160 | + */ |
|
| 1161 | + protected function _add_qtips() |
|
| 1162 | + { |
|
| 1163 | + if (isset($this->_route_config['qtips'])) { |
|
| 1164 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1165 | + //load qtip loader |
|
| 1166 | + $path = array( |
|
| 1167 | + $this->_get_dir() . '/qtips/', |
|
| 1168 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1169 | + ); |
|
| 1170 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1171 | + } |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * _set_nav_tabs |
|
| 1178 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1179 | + * |
|
| 1180 | + * @access protected |
|
| 1181 | + * @return void |
|
| 1182 | + */ |
|
| 1183 | + protected function _set_nav_tabs() |
|
| 1184 | + { |
|
| 1185 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1186 | + $i = 0; |
|
| 1187 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1188 | + if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1189 | + continue; |
|
| 1190 | + } //no nav tab for this config |
|
| 1191 | + //check for persistent flag |
|
| 1192 | + if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1193 | + continue; |
|
| 1194 | + } //nav tab is only to appear when route requested. |
|
| 1195 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1196 | + continue; |
|
| 1197 | + } //no nav tab becasue current user does not have access. |
|
| 1198 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1199 | + $this->_nav_tabs[$slug] = array( |
|
| 1200 | + 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1201 | + 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1202 | + 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1203 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1204 | + ); |
|
| 1205 | + $i++; |
|
| 1206 | + } |
|
| 1207 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1208 | + if (empty($this->_nav_tabs)) { |
|
| 1209 | + $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1210 | + 'url' => $this->admin_base_url, |
|
| 1211 | + 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1212 | + 'css_class' => 'nav-tab-active', |
|
| 1213 | + 'order' => 10, |
|
| 1214 | + ); |
|
| 1215 | + } |
|
| 1216 | + //now let's sort the tabs according to order |
|
| 1217 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * _set_current_labels |
|
| 1224 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1225 | + * |
|
| 1226 | + * @access private |
|
| 1227 | + * @return void |
|
| 1228 | + */ |
|
| 1229 | + private function _set_current_labels() |
|
| 1230 | + { |
|
| 1231 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1232 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1233 | + if (is_array($text)) { |
|
| 1234 | + foreach ($text as $sublabel => $subtext) { |
|
| 1235 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1236 | + } |
|
| 1237 | + } else { |
|
| 1238 | + $this->_labels[$label] = $text; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * verifies user access for this admin page |
|
| 1248 | + * |
|
| 1249 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1250 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1251 | + * @return BOOL|wp_die() |
|
| 1252 | + */ |
|
| 1253 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1254 | + { |
|
| 1255 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1256 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1257 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1258 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1259 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1260 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1261 | + } else { |
|
| 1262 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1263 | + } |
|
| 1264 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1265 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1266 | + if ($verify_only) { |
|
| 1267 | + return false; |
|
| 1268 | + } else { |
|
| 1269 | + if ( is_user_logged_in() ) { |
|
| 1270 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1271 | + } else { |
|
| 1272 | + return false; |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + return true; |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * admin_init_global |
|
| 1283 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1284 | + * This method executes for ALL EE Admin pages. |
|
| 1285 | + * |
|
| 1286 | + * @access public |
|
| 1287 | + * @return void |
|
| 1288 | + */ |
|
| 1289 | + public function admin_init_global() |
|
| 1290 | + { |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + /** |
|
| 1296 | + * wp_loaded_global |
|
| 1297 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1298 | + * |
|
| 1299 | + * @access public |
|
| 1300 | + * @return void |
|
| 1301 | + */ |
|
| 1302 | + public function wp_loaded() |
|
| 1303 | + { |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + /** |
|
| 1309 | + * admin_notices |
|
| 1310 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1311 | + * |
|
| 1312 | + * @access public |
|
| 1313 | + * @return void |
|
| 1314 | + */ |
|
| 1315 | + public function admin_notices_global() |
|
| 1316 | + { |
|
| 1317 | + $this->_display_no_javascript_warning(); |
|
| 1318 | + $this->_display_espresso_notices(); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + public function network_admin_notices_global() |
|
| 1324 | + { |
|
| 1325 | + $this->_display_no_javascript_warning(); |
|
| 1326 | + $this->_display_espresso_notices(); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * admin_footer_scripts_global |
|
| 1333 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1334 | + * |
|
| 1335 | + * @access public |
|
| 1336 | + * @return void |
|
| 1337 | + */ |
|
| 1338 | + public function admin_footer_scripts_global() |
|
| 1339 | + { |
|
| 1340 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1341 | + $this->_add_admin_page_overlay(); |
|
| 1342 | + //if metaboxes are present we need to add the nonce field |
|
| 1343 | + if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1344 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1345 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1346 | + } |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * admin_footer_global |
|
| 1353 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1354 | + * |
|
| 1355 | + * @access public |
|
| 1356 | + * @return void |
|
| 1357 | + */ |
|
| 1358 | + public function admin_footer_global() |
|
| 1359 | + { |
|
| 1360 | + //dialog container for dialog helper |
|
| 1361 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1362 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1363 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1364 | + $d_cont .= '</div>'; |
|
| 1365 | + echo $d_cont; |
|
| 1366 | + //help tour stuff? |
|
| 1367 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1368 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1369 | + } |
|
| 1370 | + //current set timezone for timezone js |
|
| 1371 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1378 | + * For child classes: |
|
| 1379 | + * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1380 | + * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1381 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1382 | + * 'help_trigger_id' => array( |
|
| 1383 | + * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1384 | + * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1385 | + * ) |
|
| 1386 | + * ); |
|
| 1387 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1388 | + * |
|
| 1389 | + * @access protected |
|
| 1390 | + * @return string content |
|
| 1391 | + */ |
|
| 1392 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1393 | + { |
|
| 1394 | + $content = ''; |
|
| 1395 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1396 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1397 | + //loop through the array and setup content |
|
| 1398 | + foreach ($help_array as $trigger => $help) { |
|
| 1399 | + //make sure the array is setup properly |
|
| 1400 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1401 | + throw new EE_Error(__('Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1402 | + 'event_espresso')); |
|
| 1403 | + } |
|
| 1404 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1405 | + $template_args = array( |
|
| 1406 | + 'help_popup_id' => $trigger, |
|
| 1407 | + 'help_popup_title' => $help['title'], |
|
| 1408 | + 'help_popup_content' => $help['content'], |
|
| 1409 | + ); |
|
| 1410 | + $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1411 | + } |
|
| 1412 | + if ($display) { |
|
| 1413 | + echo $content; |
|
| 1414 | + } else { |
|
| 1415 | + return $content; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1423 | + * |
|
| 1424 | + * @access private |
|
| 1425 | + * @return array properly formatted array for help popup content |
|
| 1426 | + */ |
|
| 1427 | + private function _get_help_content() |
|
| 1428 | + { |
|
| 1429 | + //what is the method we're looking for? |
|
| 1430 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1431 | + //if method doesn't exist let's get out. |
|
| 1432 | + if ( ! method_exists($this, $method_name)) { |
|
| 1433 | + return array(); |
|
| 1434 | + } |
|
| 1435 | + //k we're good to go let's retrieve the help array |
|
| 1436 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1437 | + //make sure we've got an array! |
|
| 1438 | + if ( ! is_array($help_array)) { |
|
| 1439 | + throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1440 | + } |
|
| 1441 | + return $help_array; |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1448 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1449 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1450 | + * |
|
| 1451 | + * @access protected |
|
| 1452 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1453 | + * @param boolean $display if false then we return the trigger string |
|
| 1454 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1455 | + * @return string |
|
| 1456 | + */ |
|
| 1457 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1458 | + { |
|
| 1459 | + if (defined('DOING_AJAX')) { |
|
| 1460 | + return; |
|
| 1461 | + } |
|
| 1462 | + //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1463 | + $help_array = $this->_get_help_content(); |
|
| 1464 | + $help_content = ''; |
|
| 1465 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1466 | + $help_array[$trigger_id] = array( |
|
| 1467 | + 'title' => __('Missing Content', 'event_espresso'), |
|
| 1468 | + 'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1469 | + 'event_espresso'), |
|
| 1470 | + ); |
|
| 1471 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1472 | + } |
|
| 1473 | + //let's setup the trigger |
|
| 1474 | + $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1475 | + $content = $content . $help_content; |
|
| 1476 | + if ($display) { |
|
| 1477 | + echo $content; |
|
| 1478 | + } else { |
|
| 1479 | + return $content; |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * _add_global_screen_options |
|
| 1487 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1488 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1489 | + * |
|
| 1490 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1491 | + * see also WP_Screen object documents... |
|
| 1492 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1493 | + * @abstract |
|
| 1494 | + * @access private |
|
| 1495 | + * @return void |
|
| 1496 | + */ |
|
| 1497 | + private function _add_global_screen_options() |
|
| 1498 | + { |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * _add_global_feature_pointers |
|
| 1505 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1506 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1507 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1508 | + * |
|
| 1509 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1510 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1511 | + * @abstract |
|
| 1512 | + * @access protected |
|
| 1513 | + * @return void |
|
| 1514 | + */ |
|
| 1515 | + private function _add_global_feature_pointers() |
|
| 1516 | + { |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + /** |
|
| 1522 | + * load_global_scripts_styles |
|
| 1523 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1524 | + * |
|
| 1525 | + * @return void |
|
| 1526 | + */ |
|
| 1527 | + public function load_global_scripts_styles() |
|
| 1528 | + { |
|
| 1529 | + /** STYLES **/ |
|
| 1530 | + // add debugging styles |
|
| 1531 | + if (WP_DEBUG) { |
|
| 1532 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1533 | + } |
|
| 1534 | + //register all styles |
|
| 1535 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1536 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | + //helpers styles |
|
| 1538 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1539 | + //enqueue global styles |
|
| 1540 | + wp_enqueue_style('ee-admin-css'); |
|
| 1541 | + /** SCRIPTS **/ |
|
| 1542 | + //register all scripts |
|
| 1543 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | + wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | + wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1546 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | + // register jQuery Validate - see /includes/functions/wp_hooks.php |
|
| 1548 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 1549 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1550 | + //script for sorting tables |
|
| 1551 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | + //script for parsing uri's |
|
| 1553 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | + //and parsing associative serialized form elements |
|
| 1555 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | + //helpers scripts |
|
| 1557 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1558 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1559 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1560 | + wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1561 | + //google charts |
|
| 1562 | + wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1563 | + //enqueue global scripts |
|
| 1564 | + //taking care of metaboxes |
|
| 1565 | + if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) { |
|
| 1566 | + wp_enqueue_script('dashboard'); |
|
| 1567 | + } |
|
| 1568 | + //enqueue thickbox for ee help popups. default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups |
|
| 1569 | + if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) { |
|
| 1570 | + wp_enqueue_script('ee_admin_js'); |
|
| 1571 | + wp_enqueue_style('ee-admin-css'); |
|
| 1572 | + } |
|
| 1573 | + //localize script for ajax lazy loading |
|
| 1574 | + $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1575 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1576 | + /** |
|
| 1577 | + * help tour stuff |
|
| 1578 | + */ |
|
| 1579 | + if ( ! empty($this->_help_tour)) { |
|
| 1580 | + //register the js for kicking things off |
|
| 1581 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1582 | + //setup tours for the js tour object |
|
| 1583 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1584 | + $tours[] = array( |
|
| 1585 | + 'id' => $tour->get_slug(), |
|
| 1586 | + 'options' => $tour->get_options(), |
|
| 1587 | + ); |
|
| 1588 | + } |
|
| 1589 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1590 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1591 | + } |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1598 | + * |
|
| 1599 | + * @access public |
|
| 1600 | + * @return void |
|
| 1601 | + */ |
|
| 1602 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1603 | + { |
|
| 1604 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1605 | + EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso'); |
|
| 1606 | + EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1607 | + EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1608 | + EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1609 | + EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1610 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1611 | + EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1612 | + EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1613 | + EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1614 | + EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1615 | + EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1616 | + EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1617 | + EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1618 | + EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1619 | + EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1620 | + EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1621 | + EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1622 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1623 | + EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1624 | + EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1625 | + EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1626 | + EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1627 | + EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1628 | + EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1629 | + EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1630 | + EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1631 | + EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1632 | + EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1633 | + EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1634 | + EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1635 | + EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1636 | + EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1637 | + EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1638 | + EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1639 | + EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1640 | + EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1641 | + EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1642 | + EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1643 | + EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1644 | + //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance |
|
| 1645 | + //admin page when in maintenance mode and ee_admin_js is not loaded then. This works everywhere else because |
|
| 1646 | + //espresso_core is listed as a dependency of ee_admin_js. |
|
| 1647 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + /** |
|
| 1653 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1654 | + * |
|
| 1655 | + * @access public |
|
| 1656 | + * @return void |
|
| 1657 | + */ |
|
| 1658 | + public function add_xdebug_style() |
|
| 1659 | + { |
|
| 1660 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + |
|
| 1664 | + /************************/ |
|
| 1665 | + /** LIST TABLE METHODS **/ |
|
| 1666 | + /************************/ |
|
| 1667 | + /** |
|
| 1668 | + * this sets up the list table if the current view requires it. |
|
| 1669 | + * |
|
| 1670 | + * @access protected |
|
| 1671 | + * @return void |
|
| 1672 | + */ |
|
| 1673 | + protected function _set_list_table() |
|
| 1674 | + { |
|
| 1675 | + //first is this a list_table view? |
|
| 1676 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1677 | + return; |
|
| 1678 | + } //not a list_table view so get out. |
|
| 1679 | + //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1680 | + if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1681 | + //user error msg |
|
| 1682 | + $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1683 | + //developer error msg |
|
| 1684 | + $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1685 | + $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1686 | + throw new EE_Error($error_msg); |
|
| 1687 | + } |
|
| 1688 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1689 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1690 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1691 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1692 | + $this->_set_list_table_view(); |
|
| 1693 | + $this->_set_list_table_object(); |
|
| 1694 | + } |
|
| 1695 | + |
|
| 1696 | + |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * set current view for List Table |
|
| 1700 | + * |
|
| 1701 | + * @access public |
|
| 1702 | + * @return array |
|
| 1703 | + */ |
|
| 1704 | + protected function _set_list_table_view() |
|
| 1705 | + { |
|
| 1706 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1707 | + // looking at active items or dumpster diving ? |
|
| 1708 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1709 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1710 | + } else { |
|
| 1711 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1712 | + } |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + |
|
| 1716 | + |
|
| 1717 | + /** |
|
| 1718 | + * _set_list_table_object |
|
| 1719 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1720 | + * |
|
| 1721 | + * @throws \EE_Error |
|
| 1722 | + */ |
|
| 1723 | + protected function _set_list_table_object() |
|
| 1724 | + { |
|
| 1725 | + if (isset($this->_route_config['list_table'])) { |
|
| 1726 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1727 | + throw new EE_Error( |
|
| 1728 | + sprintf( |
|
| 1729 | + __( |
|
| 1730 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 1731 | + 'event_espresso' |
|
| 1732 | + ), |
|
| 1733 | + $this->_route_config['list_table'], |
|
| 1734 | + get_class($this) |
|
| 1735 | + ) |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + $list_table = $this->_route_config['list_table']; |
|
| 1739 | + $this->_list_table_object = new $list_table($this); |
|
| 1740 | + } |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + |
|
| 1745 | + /** |
|
| 1746 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1747 | + * |
|
| 1748 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1749 | + * urls. The array should be indexed by the view it is being |
|
| 1750 | + * added to. |
|
| 1751 | + * @return array |
|
| 1752 | + */ |
|
| 1753 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1754 | + { |
|
| 1755 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1756 | + if (empty($this->_views)) { |
|
| 1757 | + $this->_views = array(); |
|
| 1758 | + } |
|
| 1759 | + // cycle thru views |
|
| 1760 | + foreach ($this->_views as $key => $view) { |
|
| 1761 | + $query_args = array(); |
|
| 1762 | + // check for current view |
|
| 1763 | + $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1764 | + $query_args['action'] = $this->_req_action; |
|
| 1765 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1766 | + $query_args['status'] = $view['slug']; |
|
| 1767 | + //merge any other arguments sent in. |
|
| 1768 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 1769 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1770 | + } |
|
| 1771 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1772 | + } |
|
| 1773 | + return $this->_views; |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + |
|
| 1777 | + |
|
| 1778 | + /** |
|
| 1779 | + * _entries_per_page_dropdown |
|
| 1780 | + * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1781 | + * |
|
| 1782 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1783 | + * @access protected |
|
| 1784 | + * @param int $max_entries total number of rows in the table |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1788 | + { |
|
| 1789 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1790 | + $values = array(10, 25, 50, 100); |
|
| 1791 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1792 | + if ($max_entries) { |
|
| 1793 | + $values[] = $max_entries; |
|
| 1794 | + sort($values); |
|
| 1795 | + } |
|
| 1796 | + $entries_per_page_dropdown = ' |
|
| 1797 | 1797 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 1798 | 1798 | <label class="hide-if-no-js"> |
| 1799 | 1799 | Show |
| 1800 | 1800 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1801 | - foreach ($values as $value) { |
|
| 1802 | - if ($value < $max_entries) { |
|
| 1803 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1804 | - $entries_per_page_dropdown .= ' |
|
| 1801 | + foreach ($values as $value) { |
|
| 1802 | + if ($value < $max_entries) { |
|
| 1803 | + $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1804 | + $entries_per_page_dropdown .= ' |
|
| 1805 | 1805 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1809 | - $entries_per_page_dropdown .= ' |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1809 | + $entries_per_page_dropdown .= ' |
|
| 1810 | 1810 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 1811 | - $entries_per_page_dropdown .= ' |
|
| 1811 | + $entries_per_page_dropdown .= ' |
|
| 1812 | 1812 | </select> |
| 1813 | 1813 | entries |
| 1814 | 1814 | </label> |
| 1815 | 1815 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 1816 | 1816 | </div> |
| 1817 | 1817 | '; |
| 1818 | - return $entries_per_page_dropdown; |
|
| 1819 | - } |
|
| 1820 | - |
|
| 1821 | - |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * _set_search_attributes |
|
| 1825 | - * |
|
| 1826 | - * @access protected |
|
| 1827 | - * @return void |
|
| 1828 | - */ |
|
| 1829 | - public function _set_search_attributes() |
|
| 1830 | - { |
|
| 1831 | - $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1832 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - /*** END LIST TABLE METHODS **/ |
|
| 1836 | - /*****************************/ |
|
| 1837 | - /** |
|
| 1838 | - * _add_registered_metaboxes |
|
| 1839 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1840 | - * |
|
| 1841 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1842 | - * @access private |
|
| 1843 | - * @return void |
|
| 1844 | - */ |
|
| 1845 | - private function _add_registered_meta_boxes() |
|
| 1846 | - { |
|
| 1847 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1848 | - //we only add meta boxes if the page_route calls for it |
|
| 1849 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1850 | - && is_array( |
|
| 1851 | - $this->_route_config['metaboxes'] |
|
| 1852 | - ) |
|
| 1853 | - ) { |
|
| 1854 | - // this simply loops through the callbacks provided |
|
| 1855 | - // and checks if there is a corresponding callback registered by the child |
|
| 1856 | - // if there is then we go ahead and process the metabox loader. |
|
| 1857 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1858 | - // first check for Closures |
|
| 1859 | - if ($metabox_callback instanceof Closure) { |
|
| 1860 | - $result = $metabox_callback(); |
|
| 1861 | - } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1862 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1863 | - } else { |
|
| 1864 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1865 | - } |
|
| 1866 | - if ($result === false) { |
|
| 1867 | - // user error msg |
|
| 1868 | - $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1869 | - // developer error msg |
|
| 1870 | - $error_msg .= '||' . sprintf( |
|
| 1871 | - __( |
|
| 1872 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 1873 | - 'event_espresso' |
|
| 1874 | - ), |
|
| 1875 | - $metabox_callback |
|
| 1876 | - ); |
|
| 1877 | - throw new EE_Error($error_msg); |
|
| 1878 | - } |
|
| 1879 | - } |
|
| 1880 | - } |
|
| 1881 | - } |
|
| 1882 | - |
|
| 1883 | - |
|
| 1884 | - |
|
| 1885 | - /** |
|
| 1886 | - * _add_screen_columns |
|
| 1887 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1888 | - * |
|
| 1889 | - * @access private |
|
| 1890 | - * @return void |
|
| 1891 | - */ |
|
| 1892 | - private function _add_screen_columns() |
|
| 1893 | - { |
|
| 1894 | - if ( |
|
| 1895 | - is_array($this->_route_config) |
|
| 1896 | - && isset($this->_route_config['columns']) |
|
| 1897 | - && is_array($this->_route_config['columns']) |
|
| 1898 | - && count($this->_route_config['columns']) === 2 |
|
| 1899 | - ) { |
|
| 1900 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1901 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1902 | - $screen_id = $this->_current_screen->id; |
|
| 1903 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1904 | - $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1905 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1906 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1907 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 1908 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1909 | - //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1910 | - $this->_route_config['has_metaboxes'] = true; |
|
| 1911 | - } |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - |
|
| 1915 | - |
|
| 1916 | - /**********************************/ |
|
| 1917 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1918 | - /** |
|
| 1919 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1920 | - * loaded on. |
|
| 1921 | - */ |
|
| 1922 | - private function _espresso_news_post_box() |
|
| 1923 | - { |
|
| 1924 | - $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1925 | - add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1926 | - $this, |
|
| 1927 | - 'espresso_news_post_box', |
|
| 1928 | - ), $this->_wp_page_slug, 'side'); |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - |
|
| 1932 | - |
|
| 1933 | - /** |
|
| 1934 | - * Code for setting up espresso ratings request metabox. |
|
| 1935 | - */ |
|
| 1936 | - protected function _espresso_ratings_request() |
|
| 1937 | - { |
|
| 1938 | - if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1939 | - return ''; |
|
| 1940 | - } |
|
| 1941 | - $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1942 | - add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1943 | - $this, |
|
| 1944 | - 'espresso_ratings_request', |
|
| 1945 | - ), $this->_wp_page_slug, 'side'); |
|
| 1946 | - } |
|
| 1947 | - |
|
| 1948 | - |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * Code for setting up espresso ratings request metabox content. |
|
| 1952 | - */ |
|
| 1953 | - public function espresso_ratings_request() |
|
| 1954 | - { |
|
| 1955 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1956 | - EEH_Template::display_template($template_path, array()); |
|
| 1957 | - } |
|
| 1958 | - |
|
| 1959 | - |
|
| 1960 | - |
|
| 1961 | - public static function cached_rss_display($rss_id, $url) |
|
| 1962 | - { |
|
| 1963 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1964 | - $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1965 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1966 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1967 | - $post = '</div>' . "\n"; |
|
| 1968 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1969 | - if (false != ($output = get_transient($cache_key))) { |
|
| 1970 | - echo $pre . $output . $post; |
|
| 1971 | - return true; |
|
| 1972 | - } |
|
| 1973 | - if ( ! $doing_ajax) { |
|
| 1974 | - echo $pre . $loading . $post; |
|
| 1975 | - return false; |
|
| 1976 | - } |
|
| 1977 | - ob_start(); |
|
| 1978 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1979 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1980 | - return true; |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - |
|
| 1985 | - public function espresso_news_post_box() |
|
| 1986 | - { |
|
| 1987 | - ?> |
|
| 1818 | + return $entries_per_page_dropdown; |
|
| 1819 | + } |
|
| 1820 | + |
|
| 1821 | + |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * _set_search_attributes |
|
| 1825 | + * |
|
| 1826 | + * @access protected |
|
| 1827 | + * @return void |
|
| 1828 | + */ |
|
| 1829 | + public function _set_search_attributes() |
|
| 1830 | + { |
|
| 1831 | + $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1832 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + /*** END LIST TABLE METHODS **/ |
|
| 1836 | + /*****************************/ |
|
| 1837 | + /** |
|
| 1838 | + * _add_registered_metaboxes |
|
| 1839 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1840 | + * |
|
| 1841 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1842 | + * @access private |
|
| 1843 | + * @return void |
|
| 1844 | + */ |
|
| 1845 | + private function _add_registered_meta_boxes() |
|
| 1846 | + { |
|
| 1847 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1848 | + //we only add meta boxes if the page_route calls for it |
|
| 1849 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1850 | + && is_array( |
|
| 1851 | + $this->_route_config['metaboxes'] |
|
| 1852 | + ) |
|
| 1853 | + ) { |
|
| 1854 | + // this simply loops through the callbacks provided |
|
| 1855 | + // and checks if there is a corresponding callback registered by the child |
|
| 1856 | + // if there is then we go ahead and process the metabox loader. |
|
| 1857 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1858 | + // first check for Closures |
|
| 1859 | + if ($metabox_callback instanceof Closure) { |
|
| 1860 | + $result = $metabox_callback(); |
|
| 1861 | + } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1862 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1863 | + } else { |
|
| 1864 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1865 | + } |
|
| 1866 | + if ($result === false) { |
|
| 1867 | + // user error msg |
|
| 1868 | + $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1869 | + // developer error msg |
|
| 1870 | + $error_msg .= '||' . sprintf( |
|
| 1871 | + __( |
|
| 1872 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 1873 | + 'event_espresso' |
|
| 1874 | + ), |
|
| 1875 | + $metabox_callback |
|
| 1876 | + ); |
|
| 1877 | + throw new EE_Error($error_msg); |
|
| 1878 | + } |
|
| 1879 | + } |
|
| 1880 | + } |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + |
|
| 1884 | + |
|
| 1885 | + /** |
|
| 1886 | + * _add_screen_columns |
|
| 1887 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1888 | + * |
|
| 1889 | + * @access private |
|
| 1890 | + * @return void |
|
| 1891 | + */ |
|
| 1892 | + private function _add_screen_columns() |
|
| 1893 | + { |
|
| 1894 | + if ( |
|
| 1895 | + is_array($this->_route_config) |
|
| 1896 | + && isset($this->_route_config['columns']) |
|
| 1897 | + && is_array($this->_route_config['columns']) |
|
| 1898 | + && count($this->_route_config['columns']) === 2 |
|
| 1899 | + ) { |
|
| 1900 | + add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1901 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1902 | + $screen_id = $this->_current_screen->id; |
|
| 1903 | + $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1904 | + $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1905 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1906 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1907 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 1908 | + $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1909 | + //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1910 | + $this->_route_config['has_metaboxes'] = true; |
|
| 1911 | + } |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + |
|
| 1915 | + |
|
| 1916 | + /**********************************/ |
|
| 1917 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1918 | + /** |
|
| 1919 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1920 | + * loaded on. |
|
| 1921 | + */ |
|
| 1922 | + private function _espresso_news_post_box() |
|
| 1923 | + { |
|
| 1924 | + $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1925 | + add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1926 | + $this, |
|
| 1927 | + 'espresso_news_post_box', |
|
| 1928 | + ), $this->_wp_page_slug, 'side'); |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + |
|
| 1932 | + |
|
| 1933 | + /** |
|
| 1934 | + * Code for setting up espresso ratings request metabox. |
|
| 1935 | + */ |
|
| 1936 | + protected function _espresso_ratings_request() |
|
| 1937 | + { |
|
| 1938 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1939 | + return ''; |
|
| 1940 | + } |
|
| 1941 | + $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1942 | + add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1943 | + $this, |
|
| 1944 | + 'espresso_ratings_request', |
|
| 1945 | + ), $this->_wp_page_slug, 'side'); |
|
| 1946 | + } |
|
| 1947 | + |
|
| 1948 | + |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * Code for setting up espresso ratings request metabox content. |
|
| 1952 | + */ |
|
| 1953 | + public function espresso_ratings_request() |
|
| 1954 | + { |
|
| 1955 | + $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1956 | + EEH_Template::display_template($template_path, array()); |
|
| 1957 | + } |
|
| 1958 | + |
|
| 1959 | + |
|
| 1960 | + |
|
| 1961 | + public static function cached_rss_display($rss_id, $url) |
|
| 1962 | + { |
|
| 1963 | + $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1964 | + $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1965 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1966 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1967 | + $post = '</div>' . "\n"; |
|
| 1968 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1969 | + if (false != ($output = get_transient($cache_key))) { |
|
| 1970 | + echo $pre . $output . $post; |
|
| 1971 | + return true; |
|
| 1972 | + } |
|
| 1973 | + if ( ! $doing_ajax) { |
|
| 1974 | + echo $pre . $loading . $post; |
|
| 1975 | + return false; |
|
| 1976 | + } |
|
| 1977 | + ob_start(); |
|
| 1978 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1979 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1980 | + return true; |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + |
|
| 1985 | + public function espresso_news_post_box() |
|
| 1986 | + { |
|
| 1987 | + ?> |
|
| 1988 | 1988 | <div class="padding"> |
| 1989 | 1989 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 1990 | 1990 | <?php |
| 1991 | - // Get RSS Feed(s) |
|
| 1992 | - $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1993 | - $url = urlencode($feed_url); |
|
| 1994 | - self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1995 | - ?> |
|
| 1991 | + // Get RSS Feed(s) |
|
| 1992 | + $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1993 | + $url = urlencode($feed_url); |
|
| 1994 | + self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1995 | + ?> |
|
| 1996 | 1996 | </div> |
| 1997 | 1997 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 1998 | 1998 | </div> |
| 1999 | 1999 | <?php |
| 2000 | - } |
|
| 2001 | - |
|
| 2002 | - |
|
| 2003 | - |
|
| 2004 | - private function _espresso_links_post_box() |
|
| 2005 | - { |
|
| 2006 | - //Hiding until we actually have content to put in here... |
|
| 2007 | - //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2008 | - } |
|
| 2009 | - |
|
| 2010 | - |
|
| 2011 | - |
|
| 2012 | - public function espresso_links_post_box() |
|
| 2013 | - { |
|
| 2014 | - //Hiding until we actually have content to put in here... |
|
| 2015 | - //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2016 | - //EEH_Template::display_template( $templatepath ); |
|
| 2017 | - } |
|
| 2018 | - |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - protected function _espresso_sponsors_post_box() |
|
| 2022 | - { |
|
| 2023 | - $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2024 | - if ($show_sponsors) { |
|
| 2025 | - add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2026 | - } |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - |
|
| 2031 | - public function espresso_sponsors_post_box() |
|
| 2032 | - { |
|
| 2033 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2034 | - EEH_Template::display_template($templatepath); |
|
| 2035 | - } |
|
| 2036 | - |
|
| 2037 | - |
|
| 2038 | - |
|
| 2039 | - private function _publish_post_box() |
|
| 2040 | - { |
|
| 2041 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2042 | - //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2043 | - if ( ! empty($this->_labels['publishbox'])) { |
|
| 2044 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2045 | - } else { |
|
| 2046 | - $box_label = __('Publish', 'event_espresso'); |
|
| 2047 | - } |
|
| 2048 | - $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2049 | - add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - public function editor_overview() |
|
| 2055 | - { |
|
| 2056 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2057 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2058 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2059 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - |
|
| 2063 | - /** end of globally available metaboxes section **/ |
|
| 2064 | - /*************************************************/ |
|
| 2065 | - /** |
|
| 2066 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2067 | - * protected method. |
|
| 2068 | - * |
|
| 2069 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2070 | - * @since 4.6.0 |
|
| 2071 | - */ |
|
| 2072 | - public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2073 | - { |
|
| 2074 | - $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2075 | - } |
|
| 2076 | - |
|
| 2077 | - |
|
| 2078 | - |
|
| 2079 | - /** |
|
| 2080 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2081 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2082 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2083 | - * values for the name and id arguments. |
|
| 2084 | - * |
|
| 2085 | - * @todo Add in validation for name/id arguments. |
|
| 2086 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2087 | - * @param int $id id attached to the item published |
|
| 2088 | - * @param string $delete page route callback for the delete action |
|
| 2089 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2090 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2091 | - * @throws \EE_Error |
|
| 2092 | - */ |
|
| 2093 | - protected function _set_publish_post_box_vars( |
|
| 2094 | - $name = '', |
|
| 2095 | - $id = 0, |
|
| 2096 | - $delete = '', |
|
| 2097 | - $save_close_redirect_URL = '', |
|
| 2098 | - $both_btns = true |
|
| 2099 | - ) { |
|
| 2100 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2101 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2102 | - // create the Save & Close and Save buttons |
|
| 2103 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2104 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2105 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2106 | - if ($delete && ! empty($id)) { |
|
| 2107 | - //make sure we have a default if just true is sent. |
|
| 2108 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2109 | - $delete_link_args = array($name => $id); |
|
| 2110 | - $delete = $this->get_action_link_or_button( |
|
| 2111 | - $delete, |
|
| 2112 | - $delete, |
|
| 2113 | - $delete_link_args, |
|
| 2114 | - 'submitdelete deletion', |
|
| 2115 | - '', |
|
| 2116 | - false |
|
| 2117 | - ); |
|
| 2118 | - } |
|
| 2119 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2120 | - if ( ! empty($name) && ! empty($id)) { |
|
| 2121 | - $hidden_field_arr[$name] = array( |
|
| 2122 | - 'type' => 'hidden', |
|
| 2123 | - 'value' => $id, |
|
| 2124 | - ); |
|
| 2125 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2126 | - } else { |
|
| 2127 | - $hf = ''; |
|
| 2128 | - } |
|
| 2129 | - // add hidden field |
|
| 2130 | - $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2131 | - } |
|
| 2132 | - |
|
| 2133 | - |
|
| 2134 | - |
|
| 2135 | - /** |
|
| 2136 | - * displays an error message to ppl who have javascript disabled |
|
| 2137 | - * |
|
| 2138 | - * @access private |
|
| 2139 | - * @return string |
|
| 2140 | - */ |
|
| 2141 | - private function _display_no_javascript_warning() |
|
| 2142 | - { |
|
| 2143 | - ?> |
|
| 2000 | + } |
|
| 2001 | + |
|
| 2002 | + |
|
| 2003 | + |
|
| 2004 | + private function _espresso_links_post_box() |
|
| 2005 | + { |
|
| 2006 | + //Hiding until we actually have content to put in here... |
|
| 2007 | + //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + |
|
| 2011 | + |
|
| 2012 | + public function espresso_links_post_box() |
|
| 2013 | + { |
|
| 2014 | + //Hiding until we actually have content to put in here... |
|
| 2015 | + //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2016 | + //EEH_Template::display_template( $templatepath ); |
|
| 2017 | + } |
|
| 2018 | + |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + protected function _espresso_sponsors_post_box() |
|
| 2022 | + { |
|
| 2023 | + $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2024 | + if ($show_sponsors) { |
|
| 2025 | + add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + |
|
| 2031 | + public function espresso_sponsors_post_box() |
|
| 2032 | + { |
|
| 2033 | + $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2034 | + EEH_Template::display_template($templatepath); |
|
| 2035 | + } |
|
| 2036 | + |
|
| 2037 | + |
|
| 2038 | + |
|
| 2039 | + private function _publish_post_box() |
|
| 2040 | + { |
|
| 2041 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2042 | + //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2043 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2044 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2045 | + } else { |
|
| 2046 | + $box_label = __('Publish', 'event_espresso'); |
|
| 2047 | + } |
|
| 2048 | + $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2049 | + add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + public function editor_overview() |
|
| 2055 | + { |
|
| 2056 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2057 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2058 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2059 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + |
|
| 2063 | + /** end of globally available metaboxes section **/ |
|
| 2064 | + /*************************************************/ |
|
| 2065 | + /** |
|
| 2066 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2067 | + * protected method. |
|
| 2068 | + * |
|
| 2069 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2070 | + * @since 4.6.0 |
|
| 2071 | + */ |
|
| 2072 | + public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2073 | + { |
|
| 2074 | + $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + |
|
| 2078 | + |
|
| 2079 | + /** |
|
| 2080 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2081 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2082 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2083 | + * values for the name and id arguments. |
|
| 2084 | + * |
|
| 2085 | + * @todo Add in validation for name/id arguments. |
|
| 2086 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2087 | + * @param int $id id attached to the item published |
|
| 2088 | + * @param string $delete page route callback for the delete action |
|
| 2089 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2090 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2091 | + * @throws \EE_Error |
|
| 2092 | + */ |
|
| 2093 | + protected function _set_publish_post_box_vars( |
|
| 2094 | + $name = '', |
|
| 2095 | + $id = 0, |
|
| 2096 | + $delete = '', |
|
| 2097 | + $save_close_redirect_URL = '', |
|
| 2098 | + $both_btns = true |
|
| 2099 | + ) { |
|
| 2100 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2101 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2102 | + // create the Save & Close and Save buttons |
|
| 2103 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2104 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2105 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2106 | + if ($delete && ! empty($id)) { |
|
| 2107 | + //make sure we have a default if just true is sent. |
|
| 2108 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2109 | + $delete_link_args = array($name => $id); |
|
| 2110 | + $delete = $this->get_action_link_or_button( |
|
| 2111 | + $delete, |
|
| 2112 | + $delete, |
|
| 2113 | + $delete_link_args, |
|
| 2114 | + 'submitdelete deletion', |
|
| 2115 | + '', |
|
| 2116 | + false |
|
| 2117 | + ); |
|
| 2118 | + } |
|
| 2119 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2120 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2121 | + $hidden_field_arr[$name] = array( |
|
| 2122 | + 'type' => 'hidden', |
|
| 2123 | + 'value' => $id, |
|
| 2124 | + ); |
|
| 2125 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2126 | + } else { |
|
| 2127 | + $hf = ''; |
|
| 2128 | + } |
|
| 2129 | + // add hidden field |
|
| 2130 | + $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + |
|
| 2134 | + |
|
| 2135 | + /** |
|
| 2136 | + * displays an error message to ppl who have javascript disabled |
|
| 2137 | + * |
|
| 2138 | + * @access private |
|
| 2139 | + * @return string |
|
| 2140 | + */ |
|
| 2141 | + private function _display_no_javascript_warning() |
|
| 2142 | + { |
|
| 2143 | + ?> |
|
| 2144 | 2144 | <noscript> |
| 2145 | 2145 | <div id="no-js-message" class="error"> |
| 2146 | 2146 | <p style="font-size:1.3em;"> |
@@ -2150,1249 +2150,1249 @@ discard block |
||
| 2150 | 2150 | </div> |
| 2151 | 2151 | </noscript> |
| 2152 | 2152 | <?php |
| 2153 | - } |
|
| 2153 | + } |
|
| 2154 | 2154 | |
| 2155 | 2155 | |
| 2156 | 2156 | |
| 2157 | - /** |
|
| 2158 | - * displays espresso success and/or error notices |
|
| 2159 | - * |
|
| 2160 | - * @access private |
|
| 2161 | - * @return string |
|
| 2162 | - */ |
|
| 2163 | - private function _display_espresso_notices() |
|
| 2164 | - { |
|
| 2165 | - $notices = $this->_get_transient(true); |
|
| 2166 | - echo stripslashes($notices); |
|
| 2167 | - } |
|
| 2157 | + /** |
|
| 2158 | + * displays espresso success and/or error notices |
|
| 2159 | + * |
|
| 2160 | + * @access private |
|
| 2161 | + * @return string |
|
| 2162 | + */ |
|
| 2163 | + private function _display_espresso_notices() |
|
| 2164 | + { |
|
| 2165 | + $notices = $this->_get_transient(true); |
|
| 2166 | + echo stripslashes($notices); |
|
| 2167 | + } |
|
| 2168 | 2168 | |
| 2169 | 2169 | |
| 2170 | 2170 | |
| 2171 | - /** |
|
| 2172 | - * spinny things pacify the masses |
|
| 2173 | - * |
|
| 2174 | - * @access private |
|
| 2175 | - * @return string |
|
| 2176 | - */ |
|
| 2177 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2178 | - { |
|
| 2179 | - ?> |
|
| 2171 | + /** |
|
| 2172 | + * spinny things pacify the masses |
|
| 2173 | + * |
|
| 2174 | + * @access private |
|
| 2175 | + * @return string |
|
| 2176 | + */ |
|
| 2177 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2178 | + { |
|
| 2179 | + ?> |
|
| 2180 | 2180 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2181 | 2181 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span> |
| 2182 | 2182 | </div> |
| 2183 | 2183 | <?php |
| 2184 | - } |
|
| 2184 | + } |
|
| 2185 | 2185 | |
| 2186 | 2186 | |
| 2187 | 2187 | |
| 2188 | - /** |
|
| 2189 | - * add admin page overlay for modal boxes |
|
| 2190 | - * |
|
| 2191 | - * @access private |
|
| 2192 | - * @return string |
|
| 2193 | - */ |
|
| 2194 | - protected function _add_admin_page_overlay() |
|
| 2195 | - { |
|
| 2196 | - ?> |
|
| 2188 | + /** |
|
| 2189 | + * add admin page overlay for modal boxes |
|
| 2190 | + * |
|
| 2191 | + * @access private |
|
| 2192 | + * @return string |
|
| 2193 | + */ |
|
| 2194 | + protected function _add_admin_page_overlay() |
|
| 2195 | + { |
|
| 2196 | + ?> |
|
| 2197 | 2197 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2198 | 2198 | <?php |
| 2199 | - } |
|
| 2200 | - |
|
| 2201 | - |
|
| 2202 | - |
|
| 2203 | - /** |
|
| 2204 | - * facade for add_meta_box |
|
| 2205 | - * |
|
| 2206 | - * @param string $action where the metabox get's displayed |
|
| 2207 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2208 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2209 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2210 | - * @param string $column what metabox column |
|
| 2211 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2212 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2213 | - */ |
|
| 2214 | - public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2215 | - { |
|
| 2216 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2217 | - //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2218 | - if (empty($callback_args) && $create_func) { |
|
| 2219 | - $callback_args = array( |
|
| 2220 | - 'template_path' => $this->_template_path, |
|
| 2221 | - 'template_args' => $this->_template_args, |
|
| 2222 | - ); |
|
| 2223 | - } |
|
| 2224 | - //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2225 | - $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2226 | - 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2227 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - |
|
| 2231 | - |
|
| 2232 | - /** |
|
| 2233 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2234 | - * |
|
| 2235 | - * @return [type] [description] |
|
| 2236 | - */ |
|
| 2237 | - public function display_admin_page_with_metabox_columns() |
|
| 2238 | - { |
|
| 2239 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2240 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2241 | - //the final wrapper |
|
| 2242 | - $this->admin_page_wrapper(); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * generates HTML wrapper for an admin details page |
|
| 2249 | - * |
|
| 2250 | - * @access public |
|
| 2251 | - * @return void |
|
| 2252 | - */ |
|
| 2253 | - public function display_admin_page_with_sidebar() |
|
| 2254 | - { |
|
| 2255 | - $this->_display_admin_page(true); |
|
| 2256 | - } |
|
| 2257 | - |
|
| 2258 | - |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2262 | - * |
|
| 2263 | - * @access public |
|
| 2264 | - * @return void |
|
| 2265 | - */ |
|
| 2266 | - public function display_admin_page_with_no_sidebar() |
|
| 2267 | - { |
|
| 2268 | - $this->_display_admin_page(); |
|
| 2269 | - } |
|
| 2270 | - |
|
| 2271 | - |
|
| 2272 | - |
|
| 2273 | - /** |
|
| 2274 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2275 | - * |
|
| 2276 | - * @access public |
|
| 2277 | - * @return void |
|
| 2278 | - */ |
|
| 2279 | - public function display_about_admin_page() |
|
| 2280 | - { |
|
| 2281 | - $this->_display_admin_page(false, true); |
|
| 2282 | - } |
|
| 2283 | - |
|
| 2284 | - |
|
| 2285 | - |
|
| 2286 | - /** |
|
| 2287 | - * display_admin_page |
|
| 2288 | - * contains the code for actually displaying an admin page |
|
| 2289 | - * |
|
| 2290 | - * @access private |
|
| 2291 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2292 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2293 | - * @return void |
|
| 2294 | - */ |
|
| 2295 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2296 | - { |
|
| 2297 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2298 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2299 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2300 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2301 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2302 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2303 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2304 | - ? 'poststuff' |
|
| 2305 | - : 'espresso-default-admin'; |
|
| 2306 | - $template_path = $sidebar |
|
| 2307 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2308 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2309 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2310 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2311 | - } |
|
| 2312 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2313 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2314 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2315 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2316 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2317 | - // the final template wrapper |
|
| 2318 | - $this->admin_page_wrapper($about); |
|
| 2319 | - } |
|
| 2320 | - |
|
| 2321 | - |
|
| 2322 | - |
|
| 2323 | - /** |
|
| 2324 | - * This is used to display caf preview pages. |
|
| 2325 | - * |
|
| 2326 | - * @since 4.3.2 |
|
| 2327 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2328 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2329 | - * @return void |
|
| 2330 | - * @throws \EE_Error |
|
| 2331 | - */ |
|
| 2332 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2333 | - { |
|
| 2334 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2335 | - $this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso'); |
|
| 2336 | - $buy_now_url = add_query_arg( |
|
| 2337 | - array( |
|
| 2338 | - 'ee_ver' => 'ee4', |
|
| 2339 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2340 | - 'utm_medium' => 'link', |
|
| 2341 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2342 | - 'utm_content' => 'buy_now_button', |
|
| 2343 | - ), |
|
| 2344 | - 'http://eventespresso.com/pricing/' |
|
| 2345 | - ); |
|
| 2346 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2347 | - ? $this->get_action_link_or_button( |
|
| 2348 | - '', |
|
| 2349 | - 'buy_now', |
|
| 2350 | - array(), |
|
| 2351 | - 'button-primary button-large', |
|
| 2352 | - $buy_now_url, |
|
| 2353 | - true |
|
| 2354 | - ) |
|
| 2355 | - : $this->_template_args['preview_action_button']; |
|
| 2356 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2357 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2358 | - $template_path, |
|
| 2359 | - $this->_template_args, |
|
| 2360 | - true |
|
| 2361 | - ); |
|
| 2362 | - $this->_display_admin_page($display_sidebar); |
|
| 2363 | - } |
|
| 2364 | - |
|
| 2365 | - |
|
| 2366 | - |
|
| 2367 | - /** |
|
| 2368 | - * display_admin_list_table_page_with_sidebar |
|
| 2369 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2370 | - * |
|
| 2371 | - * @access public |
|
| 2372 | - * @return void |
|
| 2373 | - */ |
|
| 2374 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2375 | - { |
|
| 2376 | - $this->_display_admin_list_table_page(true); |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2383 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2384 | - * |
|
| 2385 | - * @access public |
|
| 2386 | - * @return void |
|
| 2387 | - */ |
|
| 2388 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2389 | - { |
|
| 2390 | - $this->_display_admin_list_table_page(); |
|
| 2391 | - } |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - |
|
| 2395 | - /** |
|
| 2396 | - * generates html wrapper for an admin_list_table page |
|
| 2397 | - * |
|
| 2398 | - * @access private |
|
| 2399 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2400 | - * @return void |
|
| 2401 | - */ |
|
| 2402 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2403 | - { |
|
| 2404 | - //setup search attributes |
|
| 2405 | - $this->_set_search_attributes(); |
|
| 2406 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2407 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2408 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2409 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2410 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2411 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2412 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2413 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2414 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2415 | - if ( ! empty($ajax_sorting_callback)) { |
|
| 2416 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2417 | - $ajax_sorting_callback . '_nonce', |
|
| 2418 | - $ajax_sorting_callback . '_nonce', |
|
| 2419 | - false, |
|
| 2420 | - false |
|
| 2421 | - ); |
|
| 2422 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2423 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2424 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2425 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2426 | - } else { |
|
| 2427 | - $sortable_list_table_form_fields = ''; |
|
| 2428 | - } |
|
| 2429 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2430 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2431 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2432 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2433 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2434 | - //display message about search results? |
|
| 2435 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2436 | - ? '<p class="ee-search-results">' |
|
| 2437 | - . sprintf( |
|
| 2438 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2439 | - '<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>' |
|
| 2440 | - ) |
|
| 2441 | - . '</p>' |
|
| 2442 | - : ''; |
|
| 2443 | - // filter before_list_table template arg |
|
| 2444 | - $this->_template_args['before_list_table'] = implode( |
|
| 2445 | - " \n", |
|
| 2446 | - (array)apply_filters( |
|
| 2447 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2448 | - (array)$this->_template_args['before_list_table'], |
|
| 2449 | - $this->page_slug, |
|
| 2450 | - $this->_req_data, |
|
| 2451 | - $this->_req_action |
|
| 2452 | - ) |
|
| 2453 | - ); |
|
| 2454 | - // filter after_list_table template arg |
|
| 2455 | - $this->_template_args['after_list_table'] = implode( |
|
| 2456 | - " \n", |
|
| 2457 | - (array)apply_filters( |
|
| 2458 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2459 | - (array)$this->_template_args['after_list_table'], |
|
| 2460 | - $this->page_slug, |
|
| 2461 | - $this->_req_data, |
|
| 2462 | - $this->_req_action |
|
| 2463 | - ) |
|
| 2464 | - ); |
|
| 2465 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2466 | - $template_path, |
|
| 2467 | - $this->_template_args, |
|
| 2468 | - true |
|
| 2469 | - ); |
|
| 2470 | - // the final template wrapper |
|
| 2471 | - if ($sidebar) { |
|
| 2472 | - $this->display_admin_page_with_sidebar(); |
|
| 2473 | - } else { |
|
| 2474 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2475 | - } |
|
| 2476 | - } |
|
| 2477 | - |
|
| 2478 | - |
|
| 2479 | - |
|
| 2480 | - /** |
|
| 2481 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2482 | - * $items are expected in an array in the following format: |
|
| 2483 | - * $legend_items = array( |
|
| 2484 | - * 'item_id' => array( |
|
| 2485 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2486 | - * 'desc' => __('localized description of item'); |
|
| 2487 | - * ) |
|
| 2488 | - * ); |
|
| 2489 | - * |
|
| 2490 | - * @param array $items see above for format of array |
|
| 2491 | - * @return string html string of legend |
|
| 2492 | - */ |
|
| 2493 | - protected function _display_legend($items) |
|
| 2494 | - { |
|
| 2495 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2496 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2497 | - return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2498 | - } |
|
| 2499 | - |
|
| 2500 | - |
|
| 2501 | - |
|
| 2502 | - /** |
|
| 2503 | - * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2504 | - * |
|
| 2505 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2506 | - * The returned json object is created from an array in the following format: |
|
| 2507 | - * array( |
|
| 2508 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2509 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2510 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2511 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2512 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2513 | - * specific template args that might be included in here) |
|
| 2514 | - * ) |
|
| 2515 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 2516 | - * @return void |
|
| 2517 | - */ |
|
| 2518 | - protected function _return_json($sticky_notices = false) |
|
| 2519 | - { |
|
| 2520 | - //make sure any EE_Error notices have been handled. |
|
| 2521 | - $this->_process_notices(array(), true, $sticky_notices); |
|
| 2522 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2523 | - unset($this->_template_args['data']); |
|
| 2524 | - $json = array( |
|
| 2525 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2526 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2527 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2528 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2529 | - 'notices' => EE_Error::get_notices(), |
|
| 2530 | - 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2531 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2532 | - 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2533 | - ); |
|
| 2534 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2535 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 2536 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 2537 | - } |
|
| 2538 | - echo wp_json_encode($json); |
|
| 2539 | - |
|
| 2540 | - exit(); |
|
| 2541 | - } |
|
| 2542 | - |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - /** |
|
| 2546 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2547 | - * |
|
| 2548 | - * @return void |
|
| 2549 | - * @throws EE_Error |
|
| 2550 | - */ |
|
| 2551 | - public function return_json() |
|
| 2552 | - { |
|
| 2553 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2554 | - $this->_return_json(); |
|
| 2555 | - } else { |
|
| 2556 | - throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2557 | - } |
|
| 2558 | - } |
|
| 2559 | - |
|
| 2560 | - |
|
| 2561 | - |
|
| 2562 | - /** |
|
| 2563 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2564 | - * |
|
| 2565 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2566 | - * @access public |
|
| 2567 | - */ |
|
| 2568 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2569 | - { |
|
| 2570 | - $this->_hook_obj = $hook_obj; |
|
| 2571 | - } |
|
| 2572 | - |
|
| 2573 | - |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2577 | - * |
|
| 2578 | - * @access public |
|
| 2579 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2580 | - * @return void |
|
| 2581 | - */ |
|
| 2582 | - public function admin_page_wrapper($about = false) |
|
| 2583 | - { |
|
| 2584 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2585 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2586 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2587 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2588 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2589 | - isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2590 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2591 | - isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2592 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2593 | - // load settings page wrapper template |
|
| 2594 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2595 | - //about page? |
|
| 2596 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2597 | - if (defined('DOING_AJAX')) { |
|
| 2598 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2599 | - $this->_return_json(); |
|
| 2600 | - } else { |
|
| 2601 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2602 | - } |
|
| 2603 | - } |
|
| 2604 | - |
|
| 2605 | - |
|
| 2606 | - |
|
| 2607 | - /** |
|
| 2608 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2609 | - * |
|
| 2610 | - * @return string html |
|
| 2611 | - */ |
|
| 2612 | - protected function _get_main_nav_tabs() |
|
| 2613 | - { |
|
| 2614 | - //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2615 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2616 | - } |
|
| 2617 | - |
|
| 2618 | - |
|
| 2619 | - |
|
| 2620 | - /** |
|
| 2621 | - * sort nav tabs |
|
| 2622 | - * |
|
| 2623 | - * @access public |
|
| 2624 | - * @param $a |
|
| 2625 | - * @param $b |
|
| 2626 | - * @return int |
|
| 2627 | - */ |
|
| 2628 | - private function _sort_nav_tabs($a, $b) |
|
| 2629 | - { |
|
| 2630 | - if ($a['order'] == $b['order']) { |
|
| 2631 | - return 0; |
|
| 2632 | - } |
|
| 2633 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - |
|
| 2638 | - /** |
|
| 2639 | - * generates HTML for the forms used on admin pages |
|
| 2640 | - * |
|
| 2641 | - * @access protected |
|
| 2642 | - * @param array $input_vars - array of input field details |
|
| 2643 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2644 | - * @return string |
|
| 2645 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2646 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2647 | - */ |
|
| 2648 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2649 | - { |
|
| 2650 | - $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2651 | - return $content; |
|
| 2652 | - } |
|
| 2653 | - |
|
| 2654 | - |
|
| 2655 | - |
|
| 2656 | - /** |
|
| 2657 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2658 | - * |
|
| 2659 | - * @access protected |
|
| 2660 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2661 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2662 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2663 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2664 | - */ |
|
| 2665 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2666 | - { |
|
| 2667 | - //make sure $text and $actions are in an array |
|
| 2668 | - $text = (array)$text; |
|
| 2669 | - $actions = (array)$actions; |
|
| 2670 | - $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2671 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2672 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2673 | - $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2674 | - $default_names = array('save', 'save_and_close'); |
|
| 2675 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2676 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2677 | - foreach ($button_text as $key => $button) { |
|
| 2678 | - $ref = $default_names[$key]; |
|
| 2679 | - $id = $this->_current_view . '_' . $ref; |
|
| 2680 | - $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2681 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2682 | - if ( ! $both) { |
|
| 2683 | - break; |
|
| 2684 | - } |
|
| 2685 | - } |
|
| 2686 | - } |
|
| 2687 | - |
|
| 2688 | - |
|
| 2689 | - |
|
| 2690 | - /** |
|
| 2691 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2692 | - * |
|
| 2693 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2694 | - * @since 4.6.0 |
|
| 2695 | - * @param string $route |
|
| 2696 | - * @param array $additional_hidden_fields |
|
| 2697 | - */ |
|
| 2698 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2699 | - { |
|
| 2700 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2701 | - } |
|
| 2702 | - |
|
| 2703 | - |
|
| 2704 | - |
|
| 2705 | - /** |
|
| 2706 | - * set form open and close tags on add/edit pages. |
|
| 2707 | - * |
|
| 2708 | - * @access protected |
|
| 2709 | - * @param string $route the route you want the form to direct to |
|
| 2710 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2711 | - * @return void |
|
| 2712 | - */ |
|
| 2713 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2714 | - { |
|
| 2715 | - if (empty($route)) { |
|
| 2716 | - $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2717 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2718 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2719 | - } |
|
| 2720 | - // open form |
|
| 2721 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2722 | - // add nonce |
|
| 2723 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2724 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2725 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2726 | - // add REQUIRED form action |
|
| 2727 | - $hidden_fields = array( |
|
| 2728 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2729 | - ); |
|
| 2730 | - // merge arrays |
|
| 2731 | - $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2732 | - // generate form fields |
|
| 2733 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2734 | - // add fields to form |
|
| 2735 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2736 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2737 | - } |
|
| 2738 | - // close form |
|
| 2739 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2740 | - } |
|
| 2741 | - |
|
| 2742 | - |
|
| 2743 | - |
|
| 2744 | - /** |
|
| 2745 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 2746 | - * discovered it would be useful for external code to have access. |
|
| 2747 | - * |
|
| 2748 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2749 | - * @since 4.5.0 |
|
| 2750 | - */ |
|
| 2751 | - public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2752 | - { |
|
| 2753 | - $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2754 | - } |
|
| 2755 | - |
|
| 2756 | - |
|
| 2757 | - |
|
| 2758 | - /** |
|
| 2759 | - * _redirect_after_action |
|
| 2760 | - * |
|
| 2761 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2762 | - * @param string $what - what the action was performed on |
|
| 2763 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2764 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2765 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2766 | - * @access protected |
|
| 2767 | - * @return void |
|
| 2768 | - */ |
|
| 2769 | - protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2770 | - { |
|
| 2771 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2772 | - //class name for actions/filters. |
|
| 2773 | - $classname = get_class($this); |
|
| 2774 | - //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2775 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2776 | - $notices = EE_Error::get_notices(false); |
|
| 2777 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2778 | - if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2779 | - EE_Error::overwrite_success(); |
|
| 2780 | - } |
|
| 2781 | - if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2782 | - // how many records affected ? more than one record ? or just one ? |
|
| 2783 | - if ($success > 1 && empty($notices['errors'])) { |
|
| 2784 | - // set plural msg |
|
| 2785 | - EE_Error::add_success( |
|
| 2786 | - sprintf( |
|
| 2787 | - __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2788 | - $what, |
|
| 2789 | - $action_desc |
|
| 2790 | - ), |
|
| 2791 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2792 | - ); |
|
| 2793 | - } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2794 | - // set singular msg |
|
| 2795 | - EE_Error::add_success( |
|
| 2796 | - sprintf( |
|
| 2797 | - __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2798 | - $what, |
|
| 2799 | - $action_desc |
|
| 2800 | - ), |
|
| 2801 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2802 | - ); |
|
| 2803 | - } |
|
| 2804 | - } |
|
| 2805 | - // check that $query_args isn't something crazy |
|
| 2806 | - if ( ! is_array($query_args)) { |
|
| 2807 | - $query_args = array(); |
|
| 2808 | - } |
|
| 2809 | - /** |
|
| 2810 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 2811 | - * redirections on save and close actions |
|
| 2812 | - * |
|
| 2813 | - * @since 4.2.0 |
|
| 2814 | - * @param array $query_args The original query_args array coming into the |
|
| 2815 | - * method. |
|
| 2816 | - */ |
|
| 2817 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2818 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2819 | - if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2820 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2821 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2822 | - // regenerate query args array from referrer URL |
|
| 2823 | - parse_str($parsed_url['query'], $query_args); |
|
| 2824 | - // correct page and action will be in the query args now |
|
| 2825 | - $redirect_url = admin_url('admin.php'); |
|
| 2826 | - } |
|
| 2827 | - //merge any default query_args set in _default_route_query_args property |
|
| 2828 | - if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2829 | - $args_to_merge = array(); |
|
| 2830 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2831 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 2832 | - if ($query_param == 'wp_referer') { |
|
| 2833 | - $query_value = (array)$query_value; |
|
| 2834 | - foreach ($query_value as $reference => $value) { |
|
| 2835 | - if (strpos($reference, 'nonce') !== false) { |
|
| 2836 | - continue; |
|
| 2837 | - } |
|
| 2838 | - //finally we will override any arguments in the referer with |
|
| 2839 | - //what might be set on the _default_route_query_args array. |
|
| 2840 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 2841 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2842 | - } else { |
|
| 2843 | - $args_to_merge[$reference] = urlencode($value); |
|
| 2844 | - } |
|
| 2845 | - } |
|
| 2846 | - continue; |
|
| 2847 | - } |
|
| 2848 | - $args_to_merge[$query_param] = $query_value; |
|
| 2849 | - } |
|
| 2850 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2851 | - //redirect. |
|
| 2852 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 2853 | - } |
|
| 2854 | - $this->_process_notices($query_args); |
|
| 2855 | - // generate redirect url |
|
| 2856 | - // if redirecting to anything other than the main page, add a nonce |
|
| 2857 | - if (isset($query_args['action'])) { |
|
| 2858 | - // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2859 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2860 | - } |
|
| 2861 | - //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2862 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2863 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2864 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2865 | - if (defined('DOING_AJAX')) { |
|
| 2866 | - $default_data = array( |
|
| 2867 | - 'close' => true, |
|
| 2868 | - 'redirect_url' => $redirect_url, |
|
| 2869 | - 'where' => 'main', |
|
| 2870 | - 'what' => 'append', |
|
| 2871 | - ); |
|
| 2872 | - $this->_template_args['success'] = $success; |
|
| 2873 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2874 | - $this->_return_json(); |
|
| 2875 | - } |
|
| 2876 | - wp_safe_redirect($redirect_url); |
|
| 2877 | - exit(); |
|
| 2878 | - } |
|
| 2879 | - |
|
| 2880 | - |
|
| 2881 | - |
|
| 2882 | - /** |
|
| 2883 | - * process any notices before redirecting (or returning ajax request) |
|
| 2884 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 2885 | - * |
|
| 2886 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2887 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2888 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2889 | - * @return void |
|
| 2890 | - */ |
|
| 2891 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2892 | - { |
|
| 2893 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2894 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2895 | - $notices = EE_Error::get_notices(false); |
|
| 2896 | - if (empty($this->_template_args['success'])) { |
|
| 2897 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2898 | - } |
|
| 2899 | - if (empty($this->_template_args['errors'])) { |
|
| 2900 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2901 | - } |
|
| 2902 | - if (empty($this->_template_args['attention'])) { |
|
| 2903 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2904 | - } |
|
| 2905 | - } |
|
| 2906 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2907 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2908 | - if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2909 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2910 | - $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2911 | - } |
|
| 2912 | - } |
|
| 2913 | - |
|
| 2914 | - |
|
| 2915 | - |
|
| 2916 | - /** |
|
| 2917 | - * get_action_link_or_button |
|
| 2918 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2919 | - * |
|
| 2920 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 2921 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2922 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2923 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2924 | - * @param string $base_url If this is not provided |
|
| 2925 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 2926 | - * Otherwise this value will be used. |
|
| 2927 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2928 | - * @return string |
|
| 2929 | - * @throws \EE_Error |
|
| 2930 | - */ |
|
| 2931 | - public function get_action_link_or_button( |
|
| 2932 | - $action, |
|
| 2933 | - $type = 'add', |
|
| 2934 | - $extra_request = array(), |
|
| 2935 | - $class = 'button-primary', |
|
| 2936 | - $base_url = '', |
|
| 2937 | - $exclude_nonce = false |
|
| 2938 | - ) { |
|
| 2939 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2940 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2941 | - throw new EE_Error( |
|
| 2942 | - sprintf( |
|
| 2943 | - __( |
|
| 2944 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 2945 | - 'event_espresso' |
|
| 2946 | - ), |
|
| 2947 | - $action |
|
| 2948 | - ) |
|
| 2949 | - ); |
|
| 2950 | - } |
|
| 2951 | - if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2952 | - throw new EE_Error( |
|
| 2953 | - sprintf( |
|
| 2954 | - __( |
|
| 2955 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2956 | - 'event_espresso' |
|
| 2957 | - ), |
|
| 2958 | - $type |
|
| 2959 | - ) |
|
| 2960 | - ); |
|
| 2961 | - } |
|
| 2962 | - //finally check user access for this button. |
|
| 2963 | - $has_access = $this->check_user_access($action, true); |
|
| 2964 | - if ( ! $has_access) { |
|
| 2965 | - return ''; |
|
| 2966 | - } |
|
| 2967 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2968 | - $query_args = array( |
|
| 2969 | - 'action' => $action, |
|
| 2970 | - ); |
|
| 2971 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2972 | - if ( ! empty($extra_request)) { |
|
| 2973 | - $query_args = array_merge($extra_request, $query_args); |
|
| 2974 | - } |
|
| 2975 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2976 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2977 | - } |
|
| 2978 | - |
|
| 2979 | - |
|
| 2980 | - |
|
| 2981 | - /** |
|
| 2982 | - * _per_page_screen_option |
|
| 2983 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2984 | - * |
|
| 2985 | - * @return void |
|
| 2986 | - */ |
|
| 2987 | - protected function _per_page_screen_option() |
|
| 2988 | - { |
|
| 2989 | - $option = 'per_page'; |
|
| 2990 | - $args = array( |
|
| 2991 | - 'label' => $this->_admin_page_title, |
|
| 2992 | - 'default' => 10, |
|
| 2993 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2994 | - ); |
|
| 2995 | - //ONLY add the screen option if the user has access to it. |
|
| 2996 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 2997 | - add_screen_option($option, $args); |
|
| 2998 | - } |
|
| 2999 | - } |
|
| 3000 | - |
|
| 3001 | - |
|
| 3002 | - |
|
| 3003 | - /** |
|
| 3004 | - * set_per_page_screen_option |
|
| 3005 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3006 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3007 | - * |
|
| 3008 | - * @access private |
|
| 3009 | - * @return void |
|
| 3010 | - */ |
|
| 3011 | - private function _set_per_page_screen_options() |
|
| 3012 | - { |
|
| 3013 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3014 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3015 | - if ( ! $user = wp_get_current_user()) { |
|
| 3016 | - return; |
|
| 3017 | - } |
|
| 3018 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3019 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3020 | - if ($option != sanitize_key($option)) { |
|
| 3021 | - return; |
|
| 3022 | - } |
|
| 3023 | - $map_option = $option; |
|
| 3024 | - $option = str_replace('-', '_', $option); |
|
| 3025 | - switch ($map_option) { |
|
| 3026 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3027 | - $value = (int)$value; |
|
| 3028 | - if ($value < 1 || $value > 999) { |
|
| 3029 | - return; |
|
| 3030 | - } |
|
| 3031 | - break; |
|
| 3032 | - default: |
|
| 3033 | - $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3034 | - if (false === $value) { |
|
| 3035 | - return; |
|
| 3036 | - } |
|
| 3037 | - break; |
|
| 3038 | - } |
|
| 3039 | - update_user_meta($user->ID, $option, $value); |
|
| 3040 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3041 | - exit; |
|
| 3042 | - } |
|
| 3043 | - } |
|
| 3044 | - |
|
| 3045 | - |
|
| 3046 | - |
|
| 3047 | - /** |
|
| 3048 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3049 | - * |
|
| 3050 | - * @param array $data array that will be assigned to template args. |
|
| 3051 | - */ |
|
| 3052 | - public function set_template_args($data) |
|
| 3053 | - { |
|
| 3054 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3055 | - } |
|
| 3056 | - |
|
| 3057 | - |
|
| 3058 | - |
|
| 3059 | - /** |
|
| 3060 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3061 | - * |
|
| 3062 | - * @access protected |
|
| 3063 | - * @param string $route the route that should receive the transient |
|
| 3064 | - * @param array $data the data that gets sent |
|
| 3065 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3066 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3067 | - * @return void |
|
| 3068 | - */ |
|
| 3069 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3070 | - { |
|
| 3071 | - $user_id = get_current_user_id(); |
|
| 3072 | - if ( ! $skip_route_verify) { |
|
| 3073 | - $this->_verify_route($route); |
|
| 3074 | - } |
|
| 3075 | - //now let's set the string for what kind of transient we're setting |
|
| 3076 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3077 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3078 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3079 | - $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3080 | - if ($existing) { |
|
| 3081 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3082 | - } |
|
| 3083 | - if (is_multisite() && is_network_admin()) { |
|
| 3084 | - set_site_transient($transient, $data, 8); |
|
| 3085 | - } else { |
|
| 3086 | - set_transient($transient, $data, 8); |
|
| 3087 | - } |
|
| 3088 | - } |
|
| 3089 | - |
|
| 3090 | - |
|
| 3091 | - |
|
| 3092 | - /** |
|
| 3093 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3094 | - * |
|
| 3095 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3096 | - * @return mixed data |
|
| 3097 | - */ |
|
| 3098 | - protected function _get_transient($notices = false, $route = false) |
|
| 3099 | - { |
|
| 3100 | - $user_id = get_current_user_id(); |
|
| 3101 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3102 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3103 | - $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3104 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3105 | - if (is_multisite() && is_network_admin()) { |
|
| 3106 | - delete_site_transient($transient); |
|
| 3107 | - } else { |
|
| 3108 | - delete_transient($transient); |
|
| 3109 | - } |
|
| 3110 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3111 | - } |
|
| 3112 | - |
|
| 3113 | - |
|
| 3114 | - |
|
| 3115 | - /** |
|
| 3116 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3117 | - * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3118 | - * |
|
| 3119 | - * @return void |
|
| 3120 | - */ |
|
| 3121 | - protected function _transient_garbage_collection() |
|
| 3122 | - { |
|
| 3123 | - global $wpdb; |
|
| 3124 | - //retrieve all existing transients |
|
| 3125 | - $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3126 | - if ($results = $wpdb->get_results($query)) { |
|
| 3127 | - foreach ($results as $result) { |
|
| 3128 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3129 | - get_transient($transient); |
|
| 3130 | - if (is_multisite() && is_network_admin()) { |
|
| 3131 | - get_site_transient($transient); |
|
| 3132 | - } |
|
| 3133 | - } |
|
| 3134 | - } |
|
| 3135 | - } |
|
| 3136 | - |
|
| 3137 | - |
|
| 3138 | - |
|
| 3139 | - /** |
|
| 3140 | - * get_view |
|
| 3141 | - * |
|
| 3142 | - * @access public |
|
| 3143 | - * @return string content of _view property |
|
| 3144 | - */ |
|
| 3145 | - public function get_view() |
|
| 3146 | - { |
|
| 3147 | - return $this->_view; |
|
| 3148 | - } |
|
| 3149 | - |
|
| 3150 | - |
|
| 3151 | - |
|
| 3152 | - /** |
|
| 3153 | - * getter for the protected $_views property |
|
| 3154 | - * |
|
| 3155 | - * @return array |
|
| 3156 | - */ |
|
| 3157 | - public function get_views() |
|
| 3158 | - { |
|
| 3159 | - return $this->_views; |
|
| 3160 | - } |
|
| 3161 | - |
|
| 3162 | - |
|
| 3163 | - |
|
| 3164 | - /** |
|
| 3165 | - * get_current_page |
|
| 3166 | - * |
|
| 3167 | - * @access public |
|
| 3168 | - * @return string _current_page property value |
|
| 3169 | - */ |
|
| 3170 | - public function get_current_page() |
|
| 3171 | - { |
|
| 3172 | - return $this->_current_page; |
|
| 3173 | - } |
|
| 3174 | - |
|
| 3175 | - |
|
| 3176 | - |
|
| 3177 | - /** |
|
| 3178 | - * get_current_view |
|
| 3179 | - * |
|
| 3180 | - * @access public |
|
| 3181 | - * @return string _current_view property value |
|
| 3182 | - */ |
|
| 3183 | - public function get_current_view() |
|
| 3184 | - { |
|
| 3185 | - return $this->_current_view; |
|
| 3186 | - } |
|
| 3187 | - |
|
| 3188 | - |
|
| 3189 | - |
|
| 3190 | - /** |
|
| 3191 | - * get_current_screen |
|
| 3192 | - * |
|
| 3193 | - * @access public |
|
| 3194 | - * @return object The current WP_Screen object |
|
| 3195 | - */ |
|
| 3196 | - public function get_current_screen() |
|
| 3197 | - { |
|
| 3198 | - return $this->_current_screen; |
|
| 3199 | - } |
|
| 3200 | - |
|
| 3201 | - |
|
| 3202 | - |
|
| 3203 | - /** |
|
| 3204 | - * get_current_page_view_url |
|
| 3205 | - * |
|
| 3206 | - * @access public |
|
| 3207 | - * @return string This returns the url for the current_page_view. |
|
| 3208 | - */ |
|
| 3209 | - public function get_current_page_view_url() |
|
| 3210 | - { |
|
| 3211 | - return $this->_current_page_view_url; |
|
| 3212 | - } |
|
| 3213 | - |
|
| 3214 | - |
|
| 3215 | - |
|
| 3216 | - /** |
|
| 3217 | - * just returns the _req_data property |
|
| 3218 | - * |
|
| 3219 | - * @return array |
|
| 3220 | - */ |
|
| 3221 | - public function get_request_data() |
|
| 3222 | - { |
|
| 3223 | - return $this->_req_data; |
|
| 3224 | - } |
|
| 3225 | - |
|
| 3226 | - |
|
| 3227 | - |
|
| 3228 | - /** |
|
| 3229 | - * returns the _req_data protected property |
|
| 3230 | - * |
|
| 3231 | - * @return string |
|
| 3232 | - */ |
|
| 3233 | - public function get_req_action() |
|
| 3234 | - { |
|
| 3235 | - return $this->_req_action; |
|
| 3236 | - } |
|
| 3237 | - |
|
| 3238 | - |
|
| 3239 | - |
|
| 3240 | - /** |
|
| 3241 | - * @return bool value of $_is_caf property |
|
| 3242 | - */ |
|
| 3243 | - public function is_caf() |
|
| 3244 | - { |
|
| 3245 | - return $this->_is_caf; |
|
| 3246 | - } |
|
| 3247 | - |
|
| 3248 | - |
|
| 3249 | - |
|
| 3250 | - /** |
|
| 3251 | - * @return mixed |
|
| 3252 | - */ |
|
| 3253 | - public function default_espresso_metaboxes() |
|
| 3254 | - { |
|
| 3255 | - return $this->_default_espresso_metaboxes; |
|
| 3256 | - } |
|
| 3257 | - |
|
| 3258 | - |
|
| 3259 | - |
|
| 3260 | - /** |
|
| 3261 | - * @return mixed |
|
| 3262 | - */ |
|
| 3263 | - public function admin_base_url() |
|
| 3264 | - { |
|
| 3265 | - return $this->_admin_base_url; |
|
| 3266 | - } |
|
| 3267 | - |
|
| 3268 | - |
|
| 3269 | - |
|
| 3270 | - /** |
|
| 3271 | - * @return mixed |
|
| 3272 | - */ |
|
| 3273 | - public function wp_page_slug() |
|
| 3274 | - { |
|
| 3275 | - return $this->_wp_page_slug; |
|
| 3276 | - } |
|
| 3277 | - |
|
| 3278 | - |
|
| 3279 | - |
|
| 3280 | - /** |
|
| 3281 | - * updates espresso configuration settings |
|
| 3282 | - * |
|
| 3283 | - * @access protected |
|
| 3284 | - * @param string $tab |
|
| 3285 | - * @param EE_Config_Base|EE_Config $config |
|
| 3286 | - * @param string $file file where error occurred |
|
| 3287 | - * @param string $func function where error occurred |
|
| 3288 | - * @param string $line line no where error occurred |
|
| 3289 | - * @return boolean |
|
| 3290 | - */ |
|
| 3291 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3292 | - { |
|
| 3293 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 3294 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3295 | - $config->core->ee_ueip_has_notified = true; |
|
| 3296 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3297 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3298 | - update_option('ee_ueip_has_notified', true); |
|
| 3299 | - } |
|
| 3300 | - // and save it (note we're also doing the network save here) |
|
| 3301 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3302 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3303 | - if ($config_saved && $net_saved) { |
|
| 3304 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3305 | - return true; |
|
| 3306 | - } else { |
|
| 3307 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3308 | - return false; |
|
| 3309 | - } |
|
| 3310 | - } |
|
| 3311 | - |
|
| 3312 | - |
|
| 3313 | - |
|
| 3314 | - /** |
|
| 3315 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3316 | - * |
|
| 3317 | - * @return array |
|
| 3318 | - */ |
|
| 3319 | - public function get_yes_no_values() |
|
| 3320 | - { |
|
| 3321 | - return $this->_yes_no_values; |
|
| 3322 | - } |
|
| 3323 | - |
|
| 3324 | - |
|
| 3325 | - |
|
| 3326 | - protected function _get_dir() |
|
| 3327 | - { |
|
| 3328 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 3329 | - return dirname($reflector->getFileName()); |
|
| 3330 | - } |
|
| 3331 | - |
|
| 3332 | - |
|
| 3333 | - |
|
| 3334 | - /** |
|
| 3335 | - * A helper for getting a "next link". |
|
| 3336 | - * |
|
| 3337 | - * @param string $url The url to link to |
|
| 3338 | - * @param string $class The class to use. |
|
| 3339 | - * @return string |
|
| 3340 | - */ |
|
| 3341 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3342 | - { |
|
| 3343 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3344 | - } |
|
| 3345 | - |
|
| 3346 | - |
|
| 3347 | - |
|
| 3348 | - /** |
|
| 3349 | - * A helper for getting a "previous link". |
|
| 3350 | - * |
|
| 3351 | - * @param string $url The url to link to |
|
| 3352 | - * @param string $class The class to use. |
|
| 3353 | - * @return string |
|
| 3354 | - */ |
|
| 3355 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3356 | - { |
|
| 3357 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3358 | - } |
|
| 3359 | - |
|
| 3360 | - |
|
| 3361 | - |
|
| 3362 | - |
|
| 3363 | - |
|
| 3364 | - |
|
| 3365 | - |
|
| 3366 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3367 | - /** |
|
| 3368 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data |
|
| 3369 | - * array. |
|
| 3370 | - * |
|
| 3371 | - * @return bool success/fail |
|
| 3372 | - */ |
|
| 3373 | - protected function _process_resend_registration() |
|
| 3374 | - { |
|
| 3375 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3376 | - do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3377 | - return $this->_template_args['success']; |
|
| 3378 | - } |
|
| 3379 | - |
|
| 3380 | - |
|
| 3381 | - |
|
| 3382 | - /** |
|
| 3383 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3384 | - * |
|
| 3385 | - * @access protected |
|
| 3386 | - * @param \EE_Payment $payment |
|
| 3387 | - * @return bool success/fail |
|
| 3388 | - */ |
|
| 3389 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 3390 | - { |
|
| 3391 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3392 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3393 | - $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3394 | - return $this->_template_args['success']; |
|
| 3395 | - } |
|
| 2199 | + } |
|
| 2200 | + |
|
| 2201 | + |
|
| 2202 | + |
|
| 2203 | + /** |
|
| 2204 | + * facade for add_meta_box |
|
| 2205 | + * |
|
| 2206 | + * @param string $action where the metabox get's displayed |
|
| 2207 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2208 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2209 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2210 | + * @param string $column what metabox column |
|
| 2211 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2212 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2213 | + */ |
|
| 2214 | + public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2215 | + { |
|
| 2216 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2217 | + //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2218 | + if (empty($callback_args) && $create_func) { |
|
| 2219 | + $callback_args = array( |
|
| 2220 | + 'template_path' => $this->_template_path, |
|
| 2221 | + 'template_args' => $this->_template_args, |
|
| 2222 | + ); |
|
| 2223 | + } |
|
| 2224 | + //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2225 | + $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2226 | + 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2227 | + add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + |
|
| 2231 | + |
|
| 2232 | + /** |
|
| 2233 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2234 | + * |
|
| 2235 | + * @return [type] [description] |
|
| 2236 | + */ |
|
| 2237 | + public function display_admin_page_with_metabox_columns() |
|
| 2238 | + { |
|
| 2239 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2240 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2241 | + //the final wrapper |
|
| 2242 | + $this->admin_page_wrapper(); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * generates HTML wrapper for an admin details page |
|
| 2249 | + * |
|
| 2250 | + * @access public |
|
| 2251 | + * @return void |
|
| 2252 | + */ |
|
| 2253 | + public function display_admin_page_with_sidebar() |
|
| 2254 | + { |
|
| 2255 | + $this->_display_admin_page(true); |
|
| 2256 | + } |
|
| 2257 | + |
|
| 2258 | + |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2262 | + * |
|
| 2263 | + * @access public |
|
| 2264 | + * @return void |
|
| 2265 | + */ |
|
| 2266 | + public function display_admin_page_with_no_sidebar() |
|
| 2267 | + { |
|
| 2268 | + $this->_display_admin_page(); |
|
| 2269 | + } |
|
| 2270 | + |
|
| 2271 | + |
|
| 2272 | + |
|
| 2273 | + /** |
|
| 2274 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2275 | + * |
|
| 2276 | + * @access public |
|
| 2277 | + * @return void |
|
| 2278 | + */ |
|
| 2279 | + public function display_about_admin_page() |
|
| 2280 | + { |
|
| 2281 | + $this->_display_admin_page(false, true); |
|
| 2282 | + } |
|
| 2283 | + |
|
| 2284 | + |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * display_admin_page |
|
| 2288 | + * contains the code for actually displaying an admin page |
|
| 2289 | + * |
|
| 2290 | + * @access private |
|
| 2291 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2292 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2293 | + * @return void |
|
| 2294 | + */ |
|
| 2295 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2296 | + { |
|
| 2297 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2298 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2299 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2300 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2301 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2302 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2303 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2304 | + ? 'poststuff' |
|
| 2305 | + : 'espresso-default-admin'; |
|
| 2306 | + $template_path = $sidebar |
|
| 2307 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2308 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2309 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2310 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2311 | + } |
|
| 2312 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2313 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2314 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2315 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2316 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2317 | + // the final template wrapper |
|
| 2318 | + $this->admin_page_wrapper($about); |
|
| 2319 | + } |
|
| 2320 | + |
|
| 2321 | + |
|
| 2322 | + |
|
| 2323 | + /** |
|
| 2324 | + * This is used to display caf preview pages. |
|
| 2325 | + * |
|
| 2326 | + * @since 4.3.2 |
|
| 2327 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2328 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2329 | + * @return void |
|
| 2330 | + * @throws \EE_Error |
|
| 2331 | + */ |
|
| 2332 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2333 | + { |
|
| 2334 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2335 | + $this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso'); |
|
| 2336 | + $buy_now_url = add_query_arg( |
|
| 2337 | + array( |
|
| 2338 | + 'ee_ver' => 'ee4', |
|
| 2339 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2340 | + 'utm_medium' => 'link', |
|
| 2341 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2342 | + 'utm_content' => 'buy_now_button', |
|
| 2343 | + ), |
|
| 2344 | + 'http://eventespresso.com/pricing/' |
|
| 2345 | + ); |
|
| 2346 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2347 | + ? $this->get_action_link_or_button( |
|
| 2348 | + '', |
|
| 2349 | + 'buy_now', |
|
| 2350 | + array(), |
|
| 2351 | + 'button-primary button-large', |
|
| 2352 | + $buy_now_url, |
|
| 2353 | + true |
|
| 2354 | + ) |
|
| 2355 | + : $this->_template_args['preview_action_button']; |
|
| 2356 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2357 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2358 | + $template_path, |
|
| 2359 | + $this->_template_args, |
|
| 2360 | + true |
|
| 2361 | + ); |
|
| 2362 | + $this->_display_admin_page($display_sidebar); |
|
| 2363 | + } |
|
| 2364 | + |
|
| 2365 | + |
|
| 2366 | + |
|
| 2367 | + /** |
|
| 2368 | + * display_admin_list_table_page_with_sidebar |
|
| 2369 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2370 | + * |
|
| 2371 | + * @access public |
|
| 2372 | + * @return void |
|
| 2373 | + */ |
|
| 2374 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2375 | + { |
|
| 2376 | + $this->_display_admin_list_table_page(true); |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2383 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2384 | + * |
|
| 2385 | + * @access public |
|
| 2386 | + * @return void |
|
| 2387 | + */ |
|
| 2388 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2389 | + { |
|
| 2390 | + $this->_display_admin_list_table_page(); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + |
|
| 2395 | + /** |
|
| 2396 | + * generates html wrapper for an admin_list_table page |
|
| 2397 | + * |
|
| 2398 | + * @access private |
|
| 2399 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2400 | + * @return void |
|
| 2401 | + */ |
|
| 2402 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2403 | + { |
|
| 2404 | + //setup search attributes |
|
| 2405 | + $this->_set_search_attributes(); |
|
| 2406 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2407 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2408 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2409 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2410 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2411 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2412 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2413 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2414 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2415 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2416 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2417 | + $ajax_sorting_callback . '_nonce', |
|
| 2418 | + $ajax_sorting_callback . '_nonce', |
|
| 2419 | + false, |
|
| 2420 | + false |
|
| 2421 | + ); |
|
| 2422 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2423 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2424 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2425 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2426 | + } else { |
|
| 2427 | + $sortable_list_table_form_fields = ''; |
|
| 2428 | + } |
|
| 2429 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2430 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2431 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2432 | + $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2433 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2434 | + //display message about search results? |
|
| 2435 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2436 | + ? '<p class="ee-search-results">' |
|
| 2437 | + . sprintf( |
|
| 2438 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2439 | + '<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>' |
|
| 2440 | + ) |
|
| 2441 | + . '</p>' |
|
| 2442 | + : ''; |
|
| 2443 | + // filter before_list_table template arg |
|
| 2444 | + $this->_template_args['before_list_table'] = implode( |
|
| 2445 | + " \n", |
|
| 2446 | + (array)apply_filters( |
|
| 2447 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2448 | + (array)$this->_template_args['before_list_table'], |
|
| 2449 | + $this->page_slug, |
|
| 2450 | + $this->_req_data, |
|
| 2451 | + $this->_req_action |
|
| 2452 | + ) |
|
| 2453 | + ); |
|
| 2454 | + // filter after_list_table template arg |
|
| 2455 | + $this->_template_args['after_list_table'] = implode( |
|
| 2456 | + " \n", |
|
| 2457 | + (array)apply_filters( |
|
| 2458 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2459 | + (array)$this->_template_args['after_list_table'], |
|
| 2460 | + $this->page_slug, |
|
| 2461 | + $this->_req_data, |
|
| 2462 | + $this->_req_action |
|
| 2463 | + ) |
|
| 2464 | + ); |
|
| 2465 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2466 | + $template_path, |
|
| 2467 | + $this->_template_args, |
|
| 2468 | + true |
|
| 2469 | + ); |
|
| 2470 | + // the final template wrapper |
|
| 2471 | + if ($sidebar) { |
|
| 2472 | + $this->display_admin_page_with_sidebar(); |
|
| 2473 | + } else { |
|
| 2474 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2475 | + } |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + |
|
| 2479 | + |
|
| 2480 | + /** |
|
| 2481 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2482 | + * $items are expected in an array in the following format: |
|
| 2483 | + * $legend_items = array( |
|
| 2484 | + * 'item_id' => array( |
|
| 2485 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2486 | + * 'desc' => __('localized description of item'); |
|
| 2487 | + * ) |
|
| 2488 | + * ); |
|
| 2489 | + * |
|
| 2490 | + * @param array $items see above for format of array |
|
| 2491 | + * @return string html string of legend |
|
| 2492 | + */ |
|
| 2493 | + protected function _display_legend($items) |
|
| 2494 | + { |
|
| 2495 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2496 | + $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2497 | + return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2498 | + } |
|
| 2499 | + |
|
| 2500 | + |
|
| 2501 | + |
|
| 2502 | + /** |
|
| 2503 | + * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2504 | + * |
|
| 2505 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2506 | + * The returned json object is created from an array in the following format: |
|
| 2507 | + * array( |
|
| 2508 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2509 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2510 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2511 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2512 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2513 | + * specific template args that might be included in here) |
|
| 2514 | + * ) |
|
| 2515 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 2516 | + * @return void |
|
| 2517 | + */ |
|
| 2518 | + protected function _return_json($sticky_notices = false) |
|
| 2519 | + { |
|
| 2520 | + //make sure any EE_Error notices have been handled. |
|
| 2521 | + $this->_process_notices(array(), true, $sticky_notices); |
|
| 2522 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2523 | + unset($this->_template_args['data']); |
|
| 2524 | + $json = array( |
|
| 2525 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2526 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2527 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2528 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2529 | + 'notices' => EE_Error::get_notices(), |
|
| 2530 | + 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2531 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2532 | + 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2533 | + ); |
|
| 2534 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2535 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 2536 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 2537 | + } |
|
| 2538 | + echo wp_json_encode($json); |
|
| 2539 | + |
|
| 2540 | + exit(); |
|
| 2541 | + } |
|
| 2542 | + |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + /** |
|
| 2546 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2547 | + * |
|
| 2548 | + * @return void |
|
| 2549 | + * @throws EE_Error |
|
| 2550 | + */ |
|
| 2551 | + public function return_json() |
|
| 2552 | + { |
|
| 2553 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2554 | + $this->_return_json(); |
|
| 2555 | + } else { |
|
| 2556 | + throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2557 | + } |
|
| 2558 | + } |
|
| 2559 | + |
|
| 2560 | + |
|
| 2561 | + |
|
| 2562 | + /** |
|
| 2563 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2564 | + * |
|
| 2565 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2566 | + * @access public |
|
| 2567 | + */ |
|
| 2568 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2569 | + { |
|
| 2570 | + $this->_hook_obj = $hook_obj; |
|
| 2571 | + } |
|
| 2572 | + |
|
| 2573 | + |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2577 | + * |
|
| 2578 | + * @access public |
|
| 2579 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2580 | + * @return void |
|
| 2581 | + */ |
|
| 2582 | + public function admin_page_wrapper($about = false) |
|
| 2583 | + { |
|
| 2584 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2585 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2586 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2587 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2588 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2589 | + isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2590 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2591 | + isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2592 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2593 | + // load settings page wrapper template |
|
| 2594 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2595 | + //about page? |
|
| 2596 | + $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2597 | + if (defined('DOING_AJAX')) { |
|
| 2598 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2599 | + $this->_return_json(); |
|
| 2600 | + } else { |
|
| 2601 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2602 | + } |
|
| 2603 | + } |
|
| 2604 | + |
|
| 2605 | + |
|
| 2606 | + |
|
| 2607 | + /** |
|
| 2608 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2609 | + * |
|
| 2610 | + * @return string html |
|
| 2611 | + */ |
|
| 2612 | + protected function _get_main_nav_tabs() |
|
| 2613 | + { |
|
| 2614 | + //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2615 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2616 | + } |
|
| 2617 | + |
|
| 2618 | + |
|
| 2619 | + |
|
| 2620 | + /** |
|
| 2621 | + * sort nav tabs |
|
| 2622 | + * |
|
| 2623 | + * @access public |
|
| 2624 | + * @param $a |
|
| 2625 | + * @param $b |
|
| 2626 | + * @return int |
|
| 2627 | + */ |
|
| 2628 | + private function _sort_nav_tabs($a, $b) |
|
| 2629 | + { |
|
| 2630 | + if ($a['order'] == $b['order']) { |
|
| 2631 | + return 0; |
|
| 2632 | + } |
|
| 2633 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + |
|
| 2638 | + /** |
|
| 2639 | + * generates HTML for the forms used on admin pages |
|
| 2640 | + * |
|
| 2641 | + * @access protected |
|
| 2642 | + * @param array $input_vars - array of input field details |
|
| 2643 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2644 | + * @return string |
|
| 2645 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2646 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2647 | + */ |
|
| 2648 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2649 | + { |
|
| 2650 | + $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2651 | + return $content; |
|
| 2652 | + } |
|
| 2653 | + |
|
| 2654 | + |
|
| 2655 | + |
|
| 2656 | + /** |
|
| 2657 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2658 | + * |
|
| 2659 | + * @access protected |
|
| 2660 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2661 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2662 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2663 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2664 | + */ |
|
| 2665 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2666 | + { |
|
| 2667 | + //make sure $text and $actions are in an array |
|
| 2668 | + $text = (array)$text; |
|
| 2669 | + $actions = (array)$actions; |
|
| 2670 | + $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2671 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2672 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2673 | + $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2674 | + $default_names = array('save', 'save_and_close'); |
|
| 2675 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2676 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2677 | + foreach ($button_text as $key => $button) { |
|
| 2678 | + $ref = $default_names[$key]; |
|
| 2679 | + $id = $this->_current_view . '_' . $ref; |
|
| 2680 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2681 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2682 | + if ( ! $both) { |
|
| 2683 | + break; |
|
| 2684 | + } |
|
| 2685 | + } |
|
| 2686 | + } |
|
| 2687 | + |
|
| 2688 | + |
|
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2692 | + * |
|
| 2693 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2694 | + * @since 4.6.0 |
|
| 2695 | + * @param string $route |
|
| 2696 | + * @param array $additional_hidden_fields |
|
| 2697 | + */ |
|
| 2698 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2699 | + { |
|
| 2700 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2701 | + } |
|
| 2702 | + |
|
| 2703 | + |
|
| 2704 | + |
|
| 2705 | + /** |
|
| 2706 | + * set form open and close tags on add/edit pages. |
|
| 2707 | + * |
|
| 2708 | + * @access protected |
|
| 2709 | + * @param string $route the route you want the form to direct to |
|
| 2710 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2711 | + * @return void |
|
| 2712 | + */ |
|
| 2713 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2714 | + { |
|
| 2715 | + if (empty($route)) { |
|
| 2716 | + $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2717 | + $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2718 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2719 | + } |
|
| 2720 | + // open form |
|
| 2721 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2722 | + // add nonce |
|
| 2723 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2724 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2725 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2726 | + // add REQUIRED form action |
|
| 2727 | + $hidden_fields = array( |
|
| 2728 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2729 | + ); |
|
| 2730 | + // merge arrays |
|
| 2731 | + $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2732 | + // generate form fields |
|
| 2733 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2734 | + // add fields to form |
|
| 2735 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2736 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2737 | + } |
|
| 2738 | + // close form |
|
| 2739 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2740 | + } |
|
| 2741 | + |
|
| 2742 | + |
|
| 2743 | + |
|
| 2744 | + /** |
|
| 2745 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 2746 | + * discovered it would be useful for external code to have access. |
|
| 2747 | + * |
|
| 2748 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2749 | + * @since 4.5.0 |
|
| 2750 | + */ |
|
| 2751 | + public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2752 | + { |
|
| 2753 | + $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2754 | + } |
|
| 2755 | + |
|
| 2756 | + |
|
| 2757 | + |
|
| 2758 | + /** |
|
| 2759 | + * _redirect_after_action |
|
| 2760 | + * |
|
| 2761 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2762 | + * @param string $what - what the action was performed on |
|
| 2763 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2764 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2765 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2766 | + * @access protected |
|
| 2767 | + * @return void |
|
| 2768 | + */ |
|
| 2769 | + protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2770 | + { |
|
| 2771 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2772 | + //class name for actions/filters. |
|
| 2773 | + $classname = get_class($this); |
|
| 2774 | + //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2775 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2776 | + $notices = EE_Error::get_notices(false); |
|
| 2777 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2778 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2779 | + EE_Error::overwrite_success(); |
|
| 2780 | + } |
|
| 2781 | + if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2782 | + // how many records affected ? more than one record ? or just one ? |
|
| 2783 | + if ($success > 1 && empty($notices['errors'])) { |
|
| 2784 | + // set plural msg |
|
| 2785 | + EE_Error::add_success( |
|
| 2786 | + sprintf( |
|
| 2787 | + __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2788 | + $what, |
|
| 2789 | + $action_desc |
|
| 2790 | + ), |
|
| 2791 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2792 | + ); |
|
| 2793 | + } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2794 | + // set singular msg |
|
| 2795 | + EE_Error::add_success( |
|
| 2796 | + sprintf( |
|
| 2797 | + __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2798 | + $what, |
|
| 2799 | + $action_desc |
|
| 2800 | + ), |
|
| 2801 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2802 | + ); |
|
| 2803 | + } |
|
| 2804 | + } |
|
| 2805 | + // check that $query_args isn't something crazy |
|
| 2806 | + if ( ! is_array($query_args)) { |
|
| 2807 | + $query_args = array(); |
|
| 2808 | + } |
|
| 2809 | + /** |
|
| 2810 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 2811 | + * redirections on save and close actions |
|
| 2812 | + * |
|
| 2813 | + * @since 4.2.0 |
|
| 2814 | + * @param array $query_args The original query_args array coming into the |
|
| 2815 | + * method. |
|
| 2816 | + */ |
|
| 2817 | + do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2818 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2819 | + if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2820 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2821 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2822 | + // regenerate query args array from referrer URL |
|
| 2823 | + parse_str($parsed_url['query'], $query_args); |
|
| 2824 | + // correct page and action will be in the query args now |
|
| 2825 | + $redirect_url = admin_url('admin.php'); |
|
| 2826 | + } |
|
| 2827 | + //merge any default query_args set in _default_route_query_args property |
|
| 2828 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2829 | + $args_to_merge = array(); |
|
| 2830 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2831 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 2832 | + if ($query_param == 'wp_referer') { |
|
| 2833 | + $query_value = (array)$query_value; |
|
| 2834 | + foreach ($query_value as $reference => $value) { |
|
| 2835 | + if (strpos($reference, 'nonce') !== false) { |
|
| 2836 | + continue; |
|
| 2837 | + } |
|
| 2838 | + //finally we will override any arguments in the referer with |
|
| 2839 | + //what might be set on the _default_route_query_args array. |
|
| 2840 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 2841 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2842 | + } else { |
|
| 2843 | + $args_to_merge[$reference] = urlencode($value); |
|
| 2844 | + } |
|
| 2845 | + } |
|
| 2846 | + continue; |
|
| 2847 | + } |
|
| 2848 | + $args_to_merge[$query_param] = $query_value; |
|
| 2849 | + } |
|
| 2850 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2851 | + //redirect. |
|
| 2852 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 2853 | + } |
|
| 2854 | + $this->_process_notices($query_args); |
|
| 2855 | + // generate redirect url |
|
| 2856 | + // if redirecting to anything other than the main page, add a nonce |
|
| 2857 | + if (isset($query_args['action'])) { |
|
| 2858 | + // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2859 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2860 | + } |
|
| 2861 | + //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2862 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2863 | + $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2864 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2865 | + if (defined('DOING_AJAX')) { |
|
| 2866 | + $default_data = array( |
|
| 2867 | + 'close' => true, |
|
| 2868 | + 'redirect_url' => $redirect_url, |
|
| 2869 | + 'where' => 'main', |
|
| 2870 | + 'what' => 'append', |
|
| 2871 | + ); |
|
| 2872 | + $this->_template_args['success'] = $success; |
|
| 2873 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2874 | + $this->_return_json(); |
|
| 2875 | + } |
|
| 2876 | + wp_safe_redirect($redirect_url); |
|
| 2877 | + exit(); |
|
| 2878 | + } |
|
| 2879 | + |
|
| 2880 | + |
|
| 2881 | + |
|
| 2882 | + /** |
|
| 2883 | + * process any notices before redirecting (or returning ajax request) |
|
| 2884 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 2885 | + * |
|
| 2886 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2887 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2888 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2889 | + * @return void |
|
| 2890 | + */ |
|
| 2891 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2892 | + { |
|
| 2893 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2894 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2895 | + $notices = EE_Error::get_notices(false); |
|
| 2896 | + if (empty($this->_template_args['success'])) { |
|
| 2897 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2898 | + } |
|
| 2899 | + if (empty($this->_template_args['errors'])) { |
|
| 2900 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2901 | + } |
|
| 2902 | + if (empty($this->_template_args['attention'])) { |
|
| 2903 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2904 | + } |
|
| 2905 | + } |
|
| 2906 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2907 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2908 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2909 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2910 | + $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2911 | + } |
|
| 2912 | + } |
|
| 2913 | + |
|
| 2914 | + |
|
| 2915 | + |
|
| 2916 | + /** |
|
| 2917 | + * get_action_link_or_button |
|
| 2918 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2919 | + * |
|
| 2920 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 2921 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2922 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2923 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2924 | + * @param string $base_url If this is not provided |
|
| 2925 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 2926 | + * Otherwise this value will be used. |
|
| 2927 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2928 | + * @return string |
|
| 2929 | + * @throws \EE_Error |
|
| 2930 | + */ |
|
| 2931 | + public function get_action_link_or_button( |
|
| 2932 | + $action, |
|
| 2933 | + $type = 'add', |
|
| 2934 | + $extra_request = array(), |
|
| 2935 | + $class = 'button-primary', |
|
| 2936 | + $base_url = '', |
|
| 2937 | + $exclude_nonce = false |
|
| 2938 | + ) { |
|
| 2939 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2940 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2941 | + throw new EE_Error( |
|
| 2942 | + sprintf( |
|
| 2943 | + __( |
|
| 2944 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 2945 | + 'event_espresso' |
|
| 2946 | + ), |
|
| 2947 | + $action |
|
| 2948 | + ) |
|
| 2949 | + ); |
|
| 2950 | + } |
|
| 2951 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2952 | + throw new EE_Error( |
|
| 2953 | + sprintf( |
|
| 2954 | + __( |
|
| 2955 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2956 | + 'event_espresso' |
|
| 2957 | + ), |
|
| 2958 | + $type |
|
| 2959 | + ) |
|
| 2960 | + ); |
|
| 2961 | + } |
|
| 2962 | + //finally check user access for this button. |
|
| 2963 | + $has_access = $this->check_user_access($action, true); |
|
| 2964 | + if ( ! $has_access) { |
|
| 2965 | + return ''; |
|
| 2966 | + } |
|
| 2967 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2968 | + $query_args = array( |
|
| 2969 | + 'action' => $action, |
|
| 2970 | + ); |
|
| 2971 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2972 | + if ( ! empty($extra_request)) { |
|
| 2973 | + $query_args = array_merge($extra_request, $query_args); |
|
| 2974 | + } |
|
| 2975 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2976 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2977 | + } |
|
| 2978 | + |
|
| 2979 | + |
|
| 2980 | + |
|
| 2981 | + /** |
|
| 2982 | + * _per_page_screen_option |
|
| 2983 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2984 | + * |
|
| 2985 | + * @return void |
|
| 2986 | + */ |
|
| 2987 | + protected function _per_page_screen_option() |
|
| 2988 | + { |
|
| 2989 | + $option = 'per_page'; |
|
| 2990 | + $args = array( |
|
| 2991 | + 'label' => $this->_admin_page_title, |
|
| 2992 | + 'default' => 10, |
|
| 2993 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2994 | + ); |
|
| 2995 | + //ONLY add the screen option if the user has access to it. |
|
| 2996 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 2997 | + add_screen_option($option, $args); |
|
| 2998 | + } |
|
| 2999 | + } |
|
| 3000 | + |
|
| 3001 | + |
|
| 3002 | + |
|
| 3003 | + /** |
|
| 3004 | + * set_per_page_screen_option |
|
| 3005 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3006 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3007 | + * |
|
| 3008 | + * @access private |
|
| 3009 | + * @return void |
|
| 3010 | + */ |
|
| 3011 | + private function _set_per_page_screen_options() |
|
| 3012 | + { |
|
| 3013 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3014 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3015 | + if ( ! $user = wp_get_current_user()) { |
|
| 3016 | + return; |
|
| 3017 | + } |
|
| 3018 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3019 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3020 | + if ($option != sanitize_key($option)) { |
|
| 3021 | + return; |
|
| 3022 | + } |
|
| 3023 | + $map_option = $option; |
|
| 3024 | + $option = str_replace('-', '_', $option); |
|
| 3025 | + switch ($map_option) { |
|
| 3026 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3027 | + $value = (int)$value; |
|
| 3028 | + if ($value < 1 || $value > 999) { |
|
| 3029 | + return; |
|
| 3030 | + } |
|
| 3031 | + break; |
|
| 3032 | + default: |
|
| 3033 | + $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3034 | + if (false === $value) { |
|
| 3035 | + return; |
|
| 3036 | + } |
|
| 3037 | + break; |
|
| 3038 | + } |
|
| 3039 | + update_user_meta($user->ID, $option, $value); |
|
| 3040 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3041 | + exit; |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 3044 | + |
|
| 3045 | + |
|
| 3046 | + |
|
| 3047 | + /** |
|
| 3048 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3049 | + * |
|
| 3050 | + * @param array $data array that will be assigned to template args. |
|
| 3051 | + */ |
|
| 3052 | + public function set_template_args($data) |
|
| 3053 | + { |
|
| 3054 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3055 | + } |
|
| 3056 | + |
|
| 3057 | + |
|
| 3058 | + |
|
| 3059 | + /** |
|
| 3060 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3061 | + * |
|
| 3062 | + * @access protected |
|
| 3063 | + * @param string $route the route that should receive the transient |
|
| 3064 | + * @param array $data the data that gets sent |
|
| 3065 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3066 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3067 | + * @return void |
|
| 3068 | + */ |
|
| 3069 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3070 | + { |
|
| 3071 | + $user_id = get_current_user_id(); |
|
| 3072 | + if ( ! $skip_route_verify) { |
|
| 3073 | + $this->_verify_route($route); |
|
| 3074 | + } |
|
| 3075 | + //now let's set the string for what kind of transient we're setting |
|
| 3076 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3077 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3078 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3079 | + $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3080 | + if ($existing) { |
|
| 3081 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3082 | + } |
|
| 3083 | + if (is_multisite() && is_network_admin()) { |
|
| 3084 | + set_site_transient($transient, $data, 8); |
|
| 3085 | + } else { |
|
| 3086 | + set_transient($transient, $data, 8); |
|
| 3087 | + } |
|
| 3088 | + } |
|
| 3089 | + |
|
| 3090 | + |
|
| 3091 | + |
|
| 3092 | + /** |
|
| 3093 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3094 | + * |
|
| 3095 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3096 | + * @return mixed data |
|
| 3097 | + */ |
|
| 3098 | + protected function _get_transient($notices = false, $route = false) |
|
| 3099 | + { |
|
| 3100 | + $user_id = get_current_user_id(); |
|
| 3101 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3102 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3103 | + $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3104 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3105 | + if (is_multisite() && is_network_admin()) { |
|
| 3106 | + delete_site_transient($transient); |
|
| 3107 | + } else { |
|
| 3108 | + delete_transient($transient); |
|
| 3109 | + } |
|
| 3110 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3111 | + } |
|
| 3112 | + |
|
| 3113 | + |
|
| 3114 | + |
|
| 3115 | + /** |
|
| 3116 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3117 | + * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3118 | + * |
|
| 3119 | + * @return void |
|
| 3120 | + */ |
|
| 3121 | + protected function _transient_garbage_collection() |
|
| 3122 | + { |
|
| 3123 | + global $wpdb; |
|
| 3124 | + //retrieve all existing transients |
|
| 3125 | + $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3126 | + if ($results = $wpdb->get_results($query)) { |
|
| 3127 | + foreach ($results as $result) { |
|
| 3128 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3129 | + get_transient($transient); |
|
| 3130 | + if (is_multisite() && is_network_admin()) { |
|
| 3131 | + get_site_transient($transient); |
|
| 3132 | + } |
|
| 3133 | + } |
|
| 3134 | + } |
|
| 3135 | + } |
|
| 3136 | + |
|
| 3137 | + |
|
| 3138 | + |
|
| 3139 | + /** |
|
| 3140 | + * get_view |
|
| 3141 | + * |
|
| 3142 | + * @access public |
|
| 3143 | + * @return string content of _view property |
|
| 3144 | + */ |
|
| 3145 | + public function get_view() |
|
| 3146 | + { |
|
| 3147 | + return $this->_view; |
|
| 3148 | + } |
|
| 3149 | + |
|
| 3150 | + |
|
| 3151 | + |
|
| 3152 | + /** |
|
| 3153 | + * getter for the protected $_views property |
|
| 3154 | + * |
|
| 3155 | + * @return array |
|
| 3156 | + */ |
|
| 3157 | + public function get_views() |
|
| 3158 | + { |
|
| 3159 | + return $this->_views; |
|
| 3160 | + } |
|
| 3161 | + |
|
| 3162 | + |
|
| 3163 | + |
|
| 3164 | + /** |
|
| 3165 | + * get_current_page |
|
| 3166 | + * |
|
| 3167 | + * @access public |
|
| 3168 | + * @return string _current_page property value |
|
| 3169 | + */ |
|
| 3170 | + public function get_current_page() |
|
| 3171 | + { |
|
| 3172 | + return $this->_current_page; |
|
| 3173 | + } |
|
| 3174 | + |
|
| 3175 | + |
|
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * get_current_view |
|
| 3179 | + * |
|
| 3180 | + * @access public |
|
| 3181 | + * @return string _current_view property value |
|
| 3182 | + */ |
|
| 3183 | + public function get_current_view() |
|
| 3184 | + { |
|
| 3185 | + return $this->_current_view; |
|
| 3186 | + } |
|
| 3187 | + |
|
| 3188 | + |
|
| 3189 | + |
|
| 3190 | + /** |
|
| 3191 | + * get_current_screen |
|
| 3192 | + * |
|
| 3193 | + * @access public |
|
| 3194 | + * @return object The current WP_Screen object |
|
| 3195 | + */ |
|
| 3196 | + public function get_current_screen() |
|
| 3197 | + { |
|
| 3198 | + return $this->_current_screen; |
|
| 3199 | + } |
|
| 3200 | + |
|
| 3201 | + |
|
| 3202 | + |
|
| 3203 | + /** |
|
| 3204 | + * get_current_page_view_url |
|
| 3205 | + * |
|
| 3206 | + * @access public |
|
| 3207 | + * @return string This returns the url for the current_page_view. |
|
| 3208 | + */ |
|
| 3209 | + public function get_current_page_view_url() |
|
| 3210 | + { |
|
| 3211 | + return $this->_current_page_view_url; |
|
| 3212 | + } |
|
| 3213 | + |
|
| 3214 | + |
|
| 3215 | + |
|
| 3216 | + /** |
|
| 3217 | + * just returns the _req_data property |
|
| 3218 | + * |
|
| 3219 | + * @return array |
|
| 3220 | + */ |
|
| 3221 | + public function get_request_data() |
|
| 3222 | + { |
|
| 3223 | + return $this->_req_data; |
|
| 3224 | + } |
|
| 3225 | + |
|
| 3226 | + |
|
| 3227 | + |
|
| 3228 | + /** |
|
| 3229 | + * returns the _req_data protected property |
|
| 3230 | + * |
|
| 3231 | + * @return string |
|
| 3232 | + */ |
|
| 3233 | + public function get_req_action() |
|
| 3234 | + { |
|
| 3235 | + return $this->_req_action; |
|
| 3236 | + } |
|
| 3237 | + |
|
| 3238 | + |
|
| 3239 | + |
|
| 3240 | + /** |
|
| 3241 | + * @return bool value of $_is_caf property |
|
| 3242 | + */ |
|
| 3243 | + public function is_caf() |
|
| 3244 | + { |
|
| 3245 | + return $this->_is_caf; |
|
| 3246 | + } |
|
| 3247 | + |
|
| 3248 | + |
|
| 3249 | + |
|
| 3250 | + /** |
|
| 3251 | + * @return mixed |
|
| 3252 | + */ |
|
| 3253 | + public function default_espresso_metaboxes() |
|
| 3254 | + { |
|
| 3255 | + return $this->_default_espresso_metaboxes; |
|
| 3256 | + } |
|
| 3257 | + |
|
| 3258 | + |
|
| 3259 | + |
|
| 3260 | + /** |
|
| 3261 | + * @return mixed |
|
| 3262 | + */ |
|
| 3263 | + public function admin_base_url() |
|
| 3264 | + { |
|
| 3265 | + return $this->_admin_base_url; |
|
| 3266 | + } |
|
| 3267 | + |
|
| 3268 | + |
|
| 3269 | + |
|
| 3270 | + /** |
|
| 3271 | + * @return mixed |
|
| 3272 | + */ |
|
| 3273 | + public function wp_page_slug() |
|
| 3274 | + { |
|
| 3275 | + return $this->_wp_page_slug; |
|
| 3276 | + } |
|
| 3277 | + |
|
| 3278 | + |
|
| 3279 | + |
|
| 3280 | + /** |
|
| 3281 | + * updates espresso configuration settings |
|
| 3282 | + * |
|
| 3283 | + * @access protected |
|
| 3284 | + * @param string $tab |
|
| 3285 | + * @param EE_Config_Base|EE_Config $config |
|
| 3286 | + * @param string $file file where error occurred |
|
| 3287 | + * @param string $func function where error occurred |
|
| 3288 | + * @param string $line line no where error occurred |
|
| 3289 | + * @return boolean |
|
| 3290 | + */ |
|
| 3291 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3292 | + { |
|
| 3293 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 3294 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3295 | + $config->core->ee_ueip_has_notified = true; |
|
| 3296 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3297 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3298 | + update_option('ee_ueip_has_notified', true); |
|
| 3299 | + } |
|
| 3300 | + // and save it (note we're also doing the network save here) |
|
| 3301 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3302 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3303 | + if ($config_saved && $net_saved) { |
|
| 3304 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3305 | + return true; |
|
| 3306 | + } else { |
|
| 3307 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3308 | + return false; |
|
| 3309 | + } |
|
| 3310 | + } |
|
| 3311 | + |
|
| 3312 | + |
|
| 3313 | + |
|
| 3314 | + /** |
|
| 3315 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3316 | + * |
|
| 3317 | + * @return array |
|
| 3318 | + */ |
|
| 3319 | + public function get_yes_no_values() |
|
| 3320 | + { |
|
| 3321 | + return $this->_yes_no_values; |
|
| 3322 | + } |
|
| 3323 | + |
|
| 3324 | + |
|
| 3325 | + |
|
| 3326 | + protected function _get_dir() |
|
| 3327 | + { |
|
| 3328 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 3329 | + return dirname($reflector->getFileName()); |
|
| 3330 | + } |
|
| 3331 | + |
|
| 3332 | + |
|
| 3333 | + |
|
| 3334 | + /** |
|
| 3335 | + * A helper for getting a "next link". |
|
| 3336 | + * |
|
| 3337 | + * @param string $url The url to link to |
|
| 3338 | + * @param string $class The class to use. |
|
| 3339 | + * @return string |
|
| 3340 | + */ |
|
| 3341 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3342 | + { |
|
| 3343 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3344 | + } |
|
| 3345 | + |
|
| 3346 | + |
|
| 3347 | + |
|
| 3348 | + /** |
|
| 3349 | + * A helper for getting a "previous link". |
|
| 3350 | + * |
|
| 3351 | + * @param string $url The url to link to |
|
| 3352 | + * @param string $class The class to use. |
|
| 3353 | + * @return string |
|
| 3354 | + */ |
|
| 3355 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3356 | + { |
|
| 3357 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3358 | + } |
|
| 3359 | + |
|
| 3360 | + |
|
| 3361 | + |
|
| 3362 | + |
|
| 3363 | + |
|
| 3364 | + |
|
| 3365 | + |
|
| 3366 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3367 | + /** |
|
| 3368 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data |
|
| 3369 | + * array. |
|
| 3370 | + * |
|
| 3371 | + * @return bool success/fail |
|
| 3372 | + */ |
|
| 3373 | + protected function _process_resend_registration() |
|
| 3374 | + { |
|
| 3375 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3376 | + do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3377 | + return $this->_template_args['success']; |
|
| 3378 | + } |
|
| 3379 | + |
|
| 3380 | + |
|
| 3381 | + |
|
| 3382 | + /** |
|
| 3383 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3384 | + * |
|
| 3385 | + * @access protected |
|
| 3386 | + * @param \EE_Payment $payment |
|
| 3387 | + * @return bool success/fail |
|
| 3388 | + */ |
|
| 3389 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 3390 | + { |
|
| 3391 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3392 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3393 | + $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3394 | + return $this->_template_args['success']; |
|
| 3395 | + } |
|
| 3396 | 3396 | |
| 3397 | 3397 | |
| 3398 | 3398 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 474 | 474 | $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
| 475 | 475 | global $ee_menu_slugs; |
| 476 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 476 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 477 | 477 | if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
| 478 | 478 | return false; |
| 479 | 479 | } |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
| 489 | 489 | $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
| 490 | 490 | $this->_current_view = $this->_req_action; |
| 491 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 491 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 492 | 492 | $this->_define_page_props(); |
| 493 | 493 | $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
| 494 | 494 | //default things |
@@ -509,11 +509,11 @@ discard block |
||
| 509 | 509 | $this->_extend_page_config_for_cpt(); |
| 510 | 510 | } |
| 511 | 511 | //filter routes and page_config so addons can add their stuff. Filtering done per class |
| 512 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 512 | + $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | + $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | 514 | //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 515 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 515 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 516 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2); |
|
| 517 | 517 | } |
| 518 | 518 | //next route only if routing enabled |
| 519 | 519 | if ($this->_routing && ! defined('DOING_AJAX')) { |
@@ -523,8 +523,8 @@ discard block |
||
| 523 | 523 | if ($this->_is_UI_request) { |
| 524 | 524 | //admin_init stuff - global, all views for this page class, specific view |
| 525 | 525 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 526 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 526 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 527 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 528 | 528 | } |
| 529 | 529 | } else { |
| 530 | 530 | //hijack regular WP loading and route admin request immediately |
@@ -544,17 +544,17 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | private function _do_other_page_hooks() |
| 546 | 546 | { |
| 547 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 547 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 548 | 548 | foreach ($registered_pages as $page) { |
| 549 | 549 | //now let's setup the file name and class that should be present |
| 550 | 550 | $classname = str_replace('.class.php', '', $page); |
| 551 | 551 | //autoloaders should take care of loading file |
| 552 | 552 | if ( ! class_exists($classname)) { |
| 553 | - $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 553 | + $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | 554 | $error_msg[] = $error_msg[0] |
| 555 | 555 | . "\r\n" |
| 556 | - . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | - 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 556 | + . sprintf(esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | + 'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>'); |
|
| 558 | 558 | throw new EE_Error(implode('||', $error_msg)); |
| 559 | 559 | } |
| 560 | 560 | $a = new ReflectionClass($classname); |
@@ -590,13 +590,13 @@ discard block |
||
| 590 | 590 | //load admin_notices - global, page class, and view specific |
| 591 | 591 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 592 | 592 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 593 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 593 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 594 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 595 | 595 | } |
| 596 | 596 | //load network admin_notices - global, page class, and view specific |
| 597 | 597 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 598 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 598 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 599 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 600 | 600 | } |
| 601 | 601 | //this will save any per_page screen options if they are present |
| 602 | 602 | $this->_set_per_page_screen_options(); |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | //add screen options - global, page child class, and view specific |
| 609 | 609 | $this->_add_global_screen_options(); |
| 610 | 610 | $this->_add_screen_options(); |
| 611 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 611 | + if (method_exists($this, '_add_screen_options_'.$this->_current_view)) { |
|
| 612 | + call_user_func(array($this, '_add_screen_options_'.$this->_current_view)); |
|
| 613 | 613 | } |
| 614 | 614 | //add help tab(s) and tours- set via page_config and qtips. |
| 615 | 615 | $this->_add_help_tour(); |
@@ -618,31 +618,31 @@ discard block |
||
| 618 | 618 | //add feature_pointers - global, page child class, and view specific |
| 619 | 619 | $this->_add_feature_pointers(); |
| 620 | 620 | $this->_add_global_feature_pointers(); |
| 621 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 621 | + if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) { |
|
| 622 | + call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view)); |
|
| 623 | 623 | } |
| 624 | 624 | //enqueue scripts/styles - global, page class, and view specific |
| 625 | 625 | add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
| 626 | 626 | add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
| 627 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 627 | + if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) { |
|
| 628 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15); |
|
| 629 | 629 | } |
| 630 | 630 | add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
| 631 | 631 | //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
| 632 | 632 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
| 633 | 633 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
| 634 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 634 | + if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) { |
|
| 635 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101); |
|
| 636 | 636 | } |
| 637 | 637 | //admin footer scripts |
| 638 | 638 | add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
| 639 | 639 | add_action('admin_footer', array($this, 'admin_footer'), 100); |
| 640 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 640 | + if (method_exists($this, 'admin_footer_'.$this->_current_view)) { |
|
| 641 | + add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101); |
|
| 642 | 642 | } |
| 643 | 643 | do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
| 644 | 644 | //targeted hook |
| 645 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 645 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | // user error msg |
| 719 | 719 | $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 720 | 720 | // developer error msg |
| 721 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 721 | + $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | 722 | throw new EE_Error($error_msg); |
| 723 | 723 | } |
| 724 | 724 | // and that the requested page route exists |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | // user error msg |
| 730 | 730 | $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 731 | 731 | // developer error msg |
| 732 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 732 | + $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | 733 | throw new EE_Error($error_msg); |
| 734 | 734 | } |
| 735 | 735 | // and that a default route exists |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | // user error msg |
| 738 | 738 | $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
| 739 | 739 | // developer error msg |
| 740 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 740 | + $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | 741 | throw new EE_Error($error_msg); |
| 742 | 742 | } |
| 743 | 743 | //first lets' catch if the UI request has EVER been set. |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | // user error msg |
| 767 | 767 | $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 768 | 768 | // developer error msg |
| 769 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 769 | + $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | 770 | throw new EE_Error($error_msg); |
| 771 | 771 | } |
| 772 | 772 | } |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | // these are not the droids you are looking for !!! |
| 789 | 789 | $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
| 790 | 790 | if (WP_DEBUG) { |
| 791 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 791 | + $msg .= "\n ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | 792 | } |
| 793 | 793 | if ( ! defined('DOING_AJAX')) { |
| 794 | 794 | wp_die($msg); |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | if (strpos($key, 'nonce') !== false) { |
| 967 | 967 | continue; |
| 968 | 968 | } |
| 969 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 969 | + $args['wp_referer['.$key.']'] = $value; |
|
| 970 | 970 | } |
| 971 | 971 | } |
| 972 | 972 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | if ($tour instanceof EE_Help_Tour_final_stop) { |
| 1013 | 1013 | continue; |
| 1014 | 1014 | } |
| 1015 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1015 | + $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>'; |
|
| 1016 | 1016 | } |
| 1017 | 1017 | $tour_buttons .= implode('<br />', $tb); |
| 1018 | 1018 | $tour_buttons .= '</div></div>'; |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
| 1025 | 1025 | 'event_espresso'), $config['help_sidebar'], get_class($this))); |
| 1026 | 1026 | } |
| 1027 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1027 | + $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1028 | 1028 | $content .= $tour_buttons; //add help tour buttons. |
| 1029 | 1029 | //do we have any help tours setup? Cause if we do we want to add the buttons |
| 1030 | 1030 | $this->_current_screen->set_help_sidebar($content); |
@@ -1037,13 +1037,13 @@ discard block |
||
| 1037 | 1037 | if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
| 1038 | 1038 | $_ht['id'] = $this->page_slug; |
| 1039 | 1039 | $_ht['title'] = __('Help Tours', 'event_espresso'); |
| 1040 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1040 | + $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>'; |
|
| 1041 | 1041 | $this->_current_screen->add_help_tab($_ht); |
| 1042 | 1042 | }/**/ |
| 1043 | 1043 | if ( ! isset($config['help_tabs'])) { |
| 1044 | 1044 | return; |
| 1045 | 1045 | } //no help tabs for this route |
| 1046 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1046 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1047 | 1047 | //we're here so there ARE help tabs! |
| 1048 | 1048 | //make sure we've got what we need |
| 1049 | 1049 | if ( ! isset($cfg['title'])) { |
@@ -1058,9 +1058,9 @@ discard block |
||
| 1058 | 1058 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1059 | 1059 | //second priority goes to filename |
| 1060 | 1060 | } else if ( ! empty($cfg['filename'])) { |
| 1061 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1061 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1062 | 1062 | //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1063 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1063 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path; |
|
| 1064 | 1064 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1065 | 1065 | if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
| 1066 | 1066 | EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
@@ -1079,7 +1079,7 @@ discard block |
||
| 1079 | 1079 | return; |
| 1080 | 1080 | } |
| 1081 | 1081 | //setup config array for help tab method |
| 1082 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1082 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1083 | 1083 | $_ht = array( |
| 1084 | 1084 | 'id' => $id, |
| 1085 | 1085 | 'title' => $cfg['title'], |
@@ -1117,9 +1117,9 @@ discard block |
||
| 1117 | 1117 | } |
| 1118 | 1118 | if (isset($config['help_tour'])) { |
| 1119 | 1119 | foreach ($config['help_tour'] as $tour) { |
| 1120 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1120 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
| 1121 | 1121 | //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
| 1122 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1122 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path; |
|
| 1123 | 1123 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1124 | 1124 | if ( ! is_readable($file_path)) { |
| 1125 | 1125 | EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | require_once $file_path; |
| 1130 | 1130 | if ( ! class_exists($tour)) { |
| 1131 | 1131 | $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
| 1132 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1132 | + $error_msg[] = $error_msg[0]."\r\n".sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1133 | 1133 | 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
| 1134 | 1134 | throw new EE_Error(implode('||', $error_msg)); |
| 1135 | 1135 | } |
@@ -1161,11 +1161,11 @@ discard block |
||
| 1161 | 1161 | protected function _add_qtips() |
| 1162 | 1162 | { |
| 1163 | 1163 | if (isset($this->_route_config['qtips'])) { |
| 1164 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1164 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1165 | 1165 | //load qtip loader |
| 1166 | 1166 | $path = array( |
| 1167 | - $this->_get_dir() . '/qtips/', |
|
| 1168 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1167 | + $this->_get_dir().'/qtips/', |
|
| 1168 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1169 | 1169 | ); |
| 1170 | 1170 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1171 | 1171 | } |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | if ( ! $this->check_user_access($slug, true)) { |
| 1196 | 1196 | continue; |
| 1197 | 1197 | } //no nav tab becasue current user does not have access. |
| 1198 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1198 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1199 | 1199 | $this->_nav_tabs[$slug] = array( |
| 1200 | 1200 | 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
| 1201 | 1201 | 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
| 1202 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1202 | + 'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1203 | 1203 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1204 | 1204 | ); |
| 1205 | 1205 | $i++; |
@@ -1262,11 +1262,11 @@ discard block |
||
| 1262 | 1262 | $capability = empty($capability) ? 'manage_options' : $capability; |
| 1263 | 1263 | } |
| 1264 | 1264 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
| 1265 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1265 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1266 | 1266 | if ($verify_only) { |
| 1267 | 1267 | return false; |
| 1268 | 1268 | } else { |
| 1269 | - if ( is_user_logged_in() ) { |
|
| 1269 | + if (is_user_logged_in()) { |
|
| 1270 | 1270 | wp_die(__('You do not have access to this route.', 'event_espresso')); |
| 1271 | 1271 | } else { |
| 1272 | 1272 | return false; |
@@ -1358,7 +1358,7 @@ discard block |
||
| 1358 | 1358 | public function admin_footer_global() |
| 1359 | 1359 | { |
| 1360 | 1360 | //dialog container for dialog helper |
| 1361 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1361 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1362 | 1362 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1363 | 1363 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1364 | 1364 | $d_cont .= '</div>'; |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | echo implode('<br />', $this->_help_tour[$this->_req_action]); |
| 1369 | 1369 | } |
| 1370 | 1370 | //current set timezone for timezone js |
| 1371 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1371 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | |
@@ -1393,7 +1393,7 @@ discard block |
||
| 1393 | 1393 | { |
| 1394 | 1394 | $content = ''; |
| 1395 | 1395 | $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
| 1396 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1396 | + $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php'; |
|
| 1397 | 1397 | //loop through the array and setup content |
| 1398 | 1398 | foreach ($help_array as $trigger => $help) { |
| 1399 | 1399 | //make sure the array is setup properly |
@@ -1427,7 +1427,7 @@ discard block |
||
| 1427 | 1427 | private function _get_help_content() |
| 1428 | 1428 | { |
| 1429 | 1429 | //what is the method we're looking for? |
| 1430 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1430 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1431 | 1431 | //if method doesn't exist let's get out. |
| 1432 | 1432 | if ( ! method_exists($this, $method_name)) { |
| 1433 | 1433 | return array(); |
@@ -1471,8 +1471,8 @@ discard block |
||
| 1471 | 1471 | $help_content = $this->_set_help_popup_content($help_array, false); |
| 1472 | 1472 | } |
| 1473 | 1473 | //let's setup the trigger |
| 1474 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1475 | - $content = $content . $help_content; |
|
| 1474 | + $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1475 | + $content = $content.$help_content; |
|
| 1476 | 1476 | if ($display) { |
| 1477 | 1477 | echo $content; |
| 1478 | 1478 | } else { |
@@ -1532,32 +1532,32 @@ discard block |
||
| 1532 | 1532 | add_action('admin_head', array($this, 'add_xdebug_style')); |
| 1533 | 1533 | } |
| 1534 | 1534 | //register all styles |
| 1535 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1536 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1535 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1536 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | 1537 | //helpers styles |
| 1538 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1538 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1539 | 1539 | //enqueue global styles |
| 1540 | 1540 | wp_enqueue_style('ee-admin-css'); |
| 1541 | 1541 | /** SCRIPTS **/ |
| 1542 | 1542 | //register all scripts |
| 1543 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1546 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1543 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | + wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | + wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1546 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | 1547 | // register jQuery Validate - see /includes/functions/wp_hooks.php |
| 1548 | 1548 | add_filter('FHEE_load_jquery_validate', '__return_true'); |
| 1549 | 1549 | add_filter('FHEE_load_joyride', '__return_true'); |
| 1550 | 1550 | //script for sorting tables |
| 1551 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | 1552 | //script for parsing uri's |
| 1553 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | 1554 | //and parsing associative serialized form elements |
| 1555 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1555 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | 1556 | //helpers scripts |
| 1557 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1558 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1559 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1560 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1557 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1558 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1559 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1560 | + wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1561 | 1561 | //google charts |
| 1562 | 1562 | wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
| 1563 | 1563 | //enqueue global scripts |
@@ -1578,7 +1578,7 @@ discard block |
||
| 1578 | 1578 | */ |
| 1579 | 1579 | if ( ! empty($this->_help_tour)) { |
| 1580 | 1580 | //register the js for kicking things off |
| 1581 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1581 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1582 | 1582 | //setup tours for the js tour object |
| 1583 | 1583 | foreach ($this->_help_tour['tours'] as $tour) { |
| 1584 | 1584 | $tours[] = array( |
@@ -1677,17 +1677,17 @@ discard block |
||
| 1677 | 1677 | return; |
| 1678 | 1678 | } //not a list_table view so get out. |
| 1679 | 1679 | //list table functions are per view specific (because some admin pages might have more than one listtable!) |
| 1680 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1680 | + if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) { |
|
| 1681 | 1681 | //user error msg |
| 1682 | 1682 | $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
| 1683 | 1683 | //developer error msg |
| 1684 | - $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1685 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1684 | + $error_msg .= '||'.sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1685 | + $this->_req_action, '_set_list_table_views_'.$this->_req_action); |
|
| 1686 | 1686 | throw new EE_Error($error_msg); |
| 1687 | 1687 | } |
| 1688 | 1688 | //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 1689 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1690 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1689 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views); |
|
| 1690 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 1691 | 1691 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 1692 | 1692 | $this->_set_list_table_view(); |
| 1693 | 1693 | $this->_set_list_table_object(); |
@@ -1762,7 +1762,7 @@ discard block |
||
| 1762 | 1762 | // check for current view |
| 1763 | 1763 | $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
| 1764 | 1764 | $query_args['action'] = $this->_req_action; |
| 1765 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1765 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 1766 | 1766 | $query_args['status'] = $view['slug']; |
| 1767 | 1767 | //merge any other arguments sent in. |
| 1768 | 1768 | if (isset($extra_query_args[$view['slug']])) { |
@@ -1800,14 +1800,14 @@ discard block |
||
| 1800 | 1800 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1801 | 1801 | foreach ($values as $value) { |
| 1802 | 1802 | if ($value < $max_entries) { |
| 1803 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1803 | + $selected = $value == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1804 | 1804 | $entries_per_page_dropdown .= ' |
| 1805 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 1805 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 1806 | 1806 | } |
| 1807 | 1807 | } |
| 1808 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1808 | + $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1809 | 1809 | $entries_per_page_dropdown .= ' |
| 1810 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 1810 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 1811 | 1811 | $entries_per_page_dropdown .= ' |
| 1812 | 1812 | </select> |
| 1813 | 1813 | entries |
@@ -1829,7 +1829,7 @@ discard block |
||
| 1829 | 1829 | public function _set_search_attributes() |
| 1830 | 1830 | { |
| 1831 | 1831 | $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
| 1832 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1832 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /*** END LIST TABLE METHODS **/ |
@@ -1867,7 +1867,7 @@ discard block |
||
| 1867 | 1867 | // user error msg |
| 1868 | 1868 | $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
| 1869 | 1869 | // developer error msg |
| 1870 | - $error_msg .= '||' . sprintf( |
|
| 1870 | + $error_msg .= '||'.sprintf( |
|
| 1871 | 1871 | __( |
| 1872 | 1872 | 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
| 1873 | 1873 | 'event_espresso' |
@@ -1897,15 +1897,15 @@ discard block |
||
| 1897 | 1897 | && is_array($this->_route_config['columns']) |
| 1898 | 1898 | && count($this->_route_config['columns']) === 2 |
| 1899 | 1899 | ) { |
| 1900 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1900 | + add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1])); |
|
| 1901 | 1901 | $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
| 1902 | 1902 | $screen_id = $this->_current_screen->id; |
| 1903 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1903 | + $screen_columns = (int) get_user_option("screen_layout_$screen_id"); |
|
| 1904 | 1904 | $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
| 1905 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1905 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 1906 | 1906 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 1907 | 1907 | $this->_template_args['screen'] = $this->_current_screen; |
| 1908 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1908 | + $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php'; |
|
| 1909 | 1909 | //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
| 1910 | 1910 | $this->_route_config['has_metaboxes'] = true; |
| 1911 | 1911 | } |
@@ -1952,7 +1952,7 @@ discard block |
||
| 1952 | 1952 | */ |
| 1953 | 1953 | public function espresso_ratings_request() |
| 1954 | 1954 | { |
| 1955 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1955 | + $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'; |
|
| 1956 | 1956 | EEH_Template::display_template($template_path, array()); |
| 1957 | 1957 | } |
| 1958 | 1958 | |
@@ -1960,18 +1960,18 @@ discard block |
||
| 1960 | 1960 | |
| 1961 | 1961 | public static function cached_rss_display($rss_id, $url) |
| 1962 | 1962 | { |
| 1963 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1963 | + $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading…').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>'; |
|
| 1964 | 1964 | $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
| 1965 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1966 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1967 | - $post = '</div>' . "\n"; |
|
| 1968 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1965 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 1966 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 1967 | + $post = '</div>'."\n"; |
|
| 1968 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 1969 | 1969 | if (false != ($output = get_transient($cache_key))) { |
| 1970 | - echo $pre . $output . $post; |
|
| 1970 | + echo $pre.$output.$post; |
|
| 1971 | 1971 | return true; |
| 1972 | 1972 | } |
| 1973 | 1973 | if ( ! $doing_ajax) { |
| 1974 | - echo $pre . $loading . $post; |
|
| 1974 | + echo $pre.$loading.$post; |
|
| 1975 | 1975 | return false; |
| 1976 | 1976 | } |
| 1977 | 1977 | ob_start(); |
@@ -2030,7 +2030,7 @@ discard block |
||
| 2030 | 2030 | |
| 2031 | 2031 | public function espresso_sponsors_post_box() |
| 2032 | 2032 | { |
| 2033 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2033 | + $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2034 | 2034 | EEH_Template::display_template($templatepath); |
| 2035 | 2035 | } |
| 2036 | 2036 | |
@@ -2038,7 +2038,7 @@ discard block |
||
| 2038 | 2038 | |
| 2039 | 2039 | private function _publish_post_box() |
| 2040 | 2040 | { |
| 2041 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2041 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2042 | 2042 | //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2043 | 2043 | if ( ! empty($this->_labels['publishbox'])) { |
| 2044 | 2044 | $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
@@ -2055,7 +2055,7 @@ discard block |
||
| 2055 | 2055 | { |
| 2056 | 2056 | //if we have extra content set let's add it in if not make sure its empty |
| 2057 | 2057 | $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
| 2058 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2058 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php'; |
|
| 2059 | 2059 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2060 | 2060 | } |
| 2061 | 2061 | |
@@ -2224,7 +2224,7 @@ discard block |
||
| 2224 | 2224 | //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2225 | 2225 | $call_back_func = $create_func ? create_function('$post, $metabox', |
| 2226 | 2226 | 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
| 2227 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2227 | + add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | 2230 | |
@@ -2304,10 +2304,10 @@ discard block |
||
| 2304 | 2304 | ? 'poststuff' |
| 2305 | 2305 | : 'espresso-default-admin'; |
| 2306 | 2306 | $template_path = $sidebar |
| 2307 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2308 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2307 | + ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php' |
|
| 2308 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2309 | 2309 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2310 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2310 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2311 | 2311 | } |
| 2312 | 2312 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2313 | 2313 | $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
@@ -2353,7 +2353,7 @@ discard block |
||
| 2353 | 2353 | true |
| 2354 | 2354 | ) |
| 2355 | 2355 | : $this->_template_args['preview_action_button']; |
| 2356 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2356 | + $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php'; |
|
| 2357 | 2357 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2358 | 2358 | $template_path, |
| 2359 | 2359 | $this->_template_args, |
@@ -2404,7 +2404,7 @@ discard block |
||
| 2404 | 2404 | //setup search attributes |
| 2405 | 2405 | $this->_set_search_attributes(); |
| 2406 | 2406 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2407 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2407 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2408 | 2408 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2409 | 2409 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2410 | 2410 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2414,38 +2414,38 @@ discard block |
||
| 2414 | 2414 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2415 | 2415 | if ( ! empty($ajax_sorting_callback)) { |
| 2416 | 2416 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2417 | - $ajax_sorting_callback . '_nonce', |
|
| 2418 | - $ajax_sorting_callback . '_nonce', |
|
| 2417 | + $ajax_sorting_callback.'_nonce', |
|
| 2418 | + $ajax_sorting_callback.'_nonce', |
|
| 2419 | 2419 | false, |
| 2420 | 2420 | false |
| 2421 | 2421 | ); |
| 2422 | 2422 | // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
| 2423 | 2423 | // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
| 2424 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2425 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2424 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />'; |
|
| 2425 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />'; |
|
| 2426 | 2426 | } else { |
| 2427 | 2427 | $sortable_list_table_form_fields = ''; |
| 2428 | 2428 | } |
| 2429 | 2429 | $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
| 2430 | 2430 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
| 2431 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2432 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2431 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2432 | + $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2433 | 2433 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 2434 | 2434 | //display message about search results? |
| 2435 | 2435 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 2436 | 2436 | ? '<p class="ee-search-results">' |
| 2437 | 2437 | . sprintf( |
| 2438 | 2438 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2439 | - '<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>' |
|
| 2439 | + '<strong><em>'.trim($this->_req_data['s'], '%').'</em></strong>' |
|
| 2440 | 2440 | ) |
| 2441 | 2441 | . '</p>' |
| 2442 | 2442 | : ''; |
| 2443 | 2443 | // filter before_list_table template arg |
| 2444 | 2444 | $this->_template_args['before_list_table'] = implode( |
| 2445 | 2445 | " \n", |
| 2446 | - (array)apply_filters( |
|
| 2446 | + (array) apply_filters( |
|
| 2447 | 2447 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
| 2448 | - (array)$this->_template_args['before_list_table'], |
|
| 2448 | + (array) $this->_template_args['before_list_table'], |
|
| 2449 | 2449 | $this->page_slug, |
| 2450 | 2450 | $this->_req_data, |
| 2451 | 2451 | $this->_req_action |
@@ -2454,9 +2454,9 @@ discard block |
||
| 2454 | 2454 | // filter after_list_table template arg |
| 2455 | 2455 | $this->_template_args['after_list_table'] = implode( |
| 2456 | 2456 | " \n", |
| 2457 | - (array)apply_filters( |
|
| 2457 | + (array) apply_filters( |
|
| 2458 | 2458 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
| 2459 | - (array)$this->_template_args['after_list_table'], |
|
| 2459 | + (array) $this->_template_args['after_list_table'], |
|
| 2460 | 2460 | $this->page_slug, |
| 2461 | 2461 | $this->_req_data, |
| 2462 | 2462 | $this->_req_action |
@@ -2492,8 +2492,8 @@ discard block |
||
| 2492 | 2492 | */ |
| 2493 | 2493 | protected function _display_legend($items) |
| 2494 | 2494 | { |
| 2495 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2496 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2495 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this); |
|
| 2496 | + $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php'; |
|
| 2497 | 2497 | return EEH_Template::display_template($legend_template, $this->_template_args, true); |
| 2498 | 2498 | } |
| 2499 | 2499 | |
@@ -2585,15 +2585,15 @@ discard block |
||
| 2585 | 2585 | $this->_nav_tabs = $this->_get_main_nav_tabs(); |
| 2586 | 2586 | $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
| 2587 | 2587 | $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
| 2588 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2588 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2589 | 2589 | isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
| 2590 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2590 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2591 | 2591 | isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
| 2592 | 2592 | $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
| 2593 | 2593 | // load settings page wrapper template |
| 2594 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2594 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php'; |
|
| 2595 | 2595 | //about page? |
| 2596 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2596 | + $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path; |
|
| 2597 | 2597 | if (defined('DOING_AJAX')) { |
| 2598 | 2598 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2599 | 2599 | $this->_return_json(); |
@@ -2665,20 +2665,20 @@ discard block |
||
| 2665 | 2665 | protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
| 2666 | 2666 | { |
| 2667 | 2667 | //make sure $text and $actions are in an array |
| 2668 | - $text = (array)$text; |
|
| 2669 | - $actions = (array)$actions; |
|
| 2668 | + $text = (array) $text; |
|
| 2669 | + $actions = (array) $actions; |
|
| 2670 | 2670 | $referrer_url = empty($referrer) ? '' : $referrer; |
| 2671 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2672 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2671 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />' |
|
| 2672 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />'; |
|
| 2673 | 2673 | $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
| 2674 | 2674 | $default_names = array('save', 'save_and_close'); |
| 2675 | 2675 | //add in a hidden index for the current page (so save and close redirects properly) |
| 2676 | 2676 | $this->_template_args['save_buttons'] = $referrer_url; |
| 2677 | 2677 | foreach ($button_text as $key => $button) { |
| 2678 | 2678 | $ref = $default_names[$key]; |
| 2679 | - $id = $this->_current_view . '_' . $ref; |
|
| 2679 | + $id = $this->_current_view.'_'.$ref; |
|
| 2680 | 2680 | $name = ! empty($actions) ? $actions[$key] : $ref; |
| 2681 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2681 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />'; |
|
| 2682 | 2682 | if ( ! $both) { |
| 2683 | 2683 | break; |
| 2684 | 2684 | } |
@@ -2714,15 +2714,15 @@ discard block |
||
| 2714 | 2714 | { |
| 2715 | 2715 | if (empty($route)) { |
| 2716 | 2716 | $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
| 2717 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2718 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2717 | + $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2718 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2719 | 2719 | } |
| 2720 | 2720 | // open form |
| 2721 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2721 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >'; |
|
| 2722 | 2722 | // add nonce |
| 2723 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2723 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 2724 | 2724 | // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
| 2725 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2725 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 2726 | 2726 | // add REQUIRED form action |
| 2727 | 2727 | $hidden_fields = array( |
| 2728 | 2728 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -2732,8 +2732,8 @@ discard block |
||
| 2732 | 2732 | // generate form fields |
| 2733 | 2733 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 2734 | 2734 | // add fields to form |
| 2735 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2736 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2735 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 2736 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 2737 | 2737 | } |
| 2738 | 2738 | // close form |
| 2739 | 2739 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -2814,7 +2814,7 @@ discard block |
||
| 2814 | 2814 | * @param array $query_args The original query_args array coming into the |
| 2815 | 2815 | * method. |
| 2816 | 2816 | */ |
| 2817 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2817 | + do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args); |
|
| 2818 | 2818 | //calculate where we're going (if we have a "save and close" button pushed) |
| 2819 | 2819 | if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
| 2820 | 2820 | // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
@@ -2830,7 +2830,7 @@ discard block |
||
| 2830 | 2830 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 2831 | 2831 | //is there a wp_referer array in our _default_route_query_args property? |
| 2832 | 2832 | if ($query_param == 'wp_referer') { |
| 2833 | - $query_value = (array)$query_value; |
|
| 2833 | + $query_value = (array) $query_value; |
|
| 2834 | 2834 | foreach ($query_value as $reference => $value) { |
| 2835 | 2835 | if (strpos($reference, 'nonce') !== false) { |
| 2836 | 2836 | continue; |
@@ -2856,11 +2856,11 @@ discard block |
||
| 2856 | 2856 | // if redirecting to anything other than the main page, add a nonce |
| 2857 | 2857 | if (isset($query_args['action'])) { |
| 2858 | 2858 | // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
| 2859 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2859 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2860 | 2860 | } |
| 2861 | 2861 | //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
| 2862 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2863 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2862 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 2863 | + $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2864 | 2864 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 2865 | 2865 | if (defined('DOING_AJAX')) { |
| 2866 | 2866 | $default_data = array( |
@@ -2990,7 +2990,7 @@ discard block |
||
| 2990 | 2990 | $args = array( |
| 2991 | 2991 | 'label' => $this->_admin_page_title, |
| 2992 | 2992 | 'default' => 10, |
| 2993 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2993 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 2994 | 2994 | ); |
| 2995 | 2995 | //ONLY add the screen option if the user has access to it. |
| 2996 | 2996 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3023,8 +3023,8 @@ discard block |
||
| 3023 | 3023 | $map_option = $option; |
| 3024 | 3024 | $option = str_replace('-', '_', $option); |
| 3025 | 3025 | switch ($map_option) { |
| 3026 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3027 | - $value = (int)$value; |
|
| 3026 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3027 | + $value = (int) $value; |
|
| 3028 | 3028 | if ($value < 1 || $value > 999) { |
| 3029 | 3029 | return; |
| 3030 | 3030 | } |
@@ -3051,7 +3051,7 @@ discard block |
||
| 3051 | 3051 | */ |
| 3052 | 3052 | public function set_template_args($data) |
| 3053 | 3053 | { |
| 3054 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3054 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3055 | 3055 | } |
| 3056 | 3056 | |
| 3057 | 3057 | |
@@ -3073,12 +3073,12 @@ discard block |
||
| 3073 | 3073 | $this->_verify_route($route); |
| 3074 | 3074 | } |
| 3075 | 3075 | //now let's set the string for what kind of transient we're setting |
| 3076 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3076 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3077 | 3077 | $data = $notices ? array('notices' => $data) : $data; |
| 3078 | 3078 | //is there already a transient for this route? If there is then let's ADD to that transient |
| 3079 | 3079 | $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3080 | 3080 | if ($existing) { |
| 3081 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3081 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3082 | 3082 | } |
| 3083 | 3083 | if (is_multisite() && is_network_admin()) { |
| 3084 | 3084 | set_site_transient($transient, $data, 8); |
@@ -3099,7 +3099,7 @@ discard block |
||
| 3099 | 3099 | { |
| 3100 | 3100 | $user_id = get_current_user_id(); |
| 3101 | 3101 | $route = ! $route ? $this->_req_action : $route; |
| 3102 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3102 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3103 | 3103 | $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3104 | 3104 | //delete transient after retrieval (just in case it hasn't expired); |
| 3105 | 3105 | if (is_multisite() && is_network_admin()) { |
@@ -3340,7 +3340,7 @@ discard block |
||
| 3340 | 3340 | */ |
| 3341 | 3341 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 3342 | 3342 | { |
| 3343 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3343 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3344 | 3344 | } |
| 3345 | 3345 | |
| 3346 | 3346 | |
@@ -3354,7 +3354,7 @@ discard block |
||
| 3354 | 3354 | */ |
| 3355 | 3355 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 3356 | 3356 | { |
| 3357 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3357 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3358 | 3358 | } |
| 3359 | 3359 | |
| 3360 | 3360 | |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
| 3 | 3 | global $post; |
| 4 | -do_action( 'AHEE_event_details_before_featured_img', $post ); |
|
| 4 | +do_action('AHEE_event_details_before_featured_img', $post); |
|
| 5 | 5 | |
| 6 | -if ( has_post_thumbnail( $post->ID )) : |
|
| 7 | - if ( $img_ID = get_post_thumbnail_id( $post->ID )) : |
|
| 8 | - if ( $featured_img = wp_get_attachment_image_src( $img_ID, 'large' )) : |
|
| 9 | - $caption = esc_attr( get_post( get_post( $img_ID ))->post_excerpt ); |
|
| 6 | +if (has_post_thumbnail($post->ID)) : |
|
| 7 | + if ($img_ID = get_post_thumbnail_id($post->ID)) : |
|
| 8 | + if ($featured_img = wp_get_attachment_image_src($img_ID, 'large')) : |
|
| 9 | + $caption = esc_attr(get_post(get_post($img_ID))->post_excerpt); |
|
| 10 | 10 | ?> |
| 11 | 11 | <div id="ee-event-img-dv-<?php echo $post->ID; ?>" class="ee-event-img-dv"> |
| 12 | - <a class="ee-event-img-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target();?>> |
|
| 12 | + <a class="ee-event-img-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target(); ?>> |
|
| 13 | 13 | <img class="ee-event-img" src="<?php echo $featured_img[0]; ?>" width="<?php echo $featured_img[1]; ?>" height="<?php echo $featured_img[2]; ?>" alt="<?php echo $caption; ?>"/> |
| 14 | 14 | </a> |
| 15 | 15 | </div> |
@@ -18,4 +18,4 @@ discard block |
||
| 18 | 18 | endif; |
| 19 | 19 | endif; |
| 20 | 20 | ?> |
| 21 | -<?php do_action( 'AHEE_event_details_after_featured_img', $post );?> |
|
| 21 | +<?php do_action('AHEE_event_details_after_featured_img', $post); ?> |
|
@@ -5,9 +5,9 @@ |
||
| 5 | 5 | ?> |
| 6 | 6 | <header class="event-header"> |
| 7 | 7 | <?php echo "<{$tag} id=\"event-details-{$tag}-{$post->ID}\" class=\"entry-title\">"; ?> |
| 8 | - <a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target();?>> |
|
| 8 | + <a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target(); ?>> |
|
| 9 | 9 | <?php the_title(); ?> |
| 10 | 10 | </a> |
| 11 | 11 | <?php echo "</{$tag}"; ?> |
| 12 | - <?php if ( ! is_archive() && has_excerpt( $post->ID )): the_excerpt(); endif;?> |
|
| 12 | + <?php if ( ! is_archive() && has_excerpt($post->ID)): the_excerpt(); endif; ?> |
|
| 13 | 13 | </header> |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 5 | - exit( 'No direct script access allowed' ); |
|
| 5 | + exit( 'No direct script access allowed' ); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,494 +19,494 @@ discard block |
||
| 19 | 19 | class DisplayTicketSelector |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * event that ticket selector is being generated for |
|
| 24 | - * |
|
| 25 | - * @access protected |
|
| 26 | - * @var \EE_Event $event |
|
| 27 | - */ |
|
| 28 | - protected $event; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
| 32 | - * |
|
| 33 | - * @var bool $iframe |
|
| 34 | - */ |
|
| 35 | - protected $iframe = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * max attendees that can register for event at one time |
|
| 39 | - * |
|
| 40 | - * @var int $max_attendees |
|
| 41 | - */ |
|
| 42 | - private $max_attendees = EE_INF; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param boolean $iframe |
|
| 48 | - */ |
|
| 49 | - public function setIframe( $iframe = true ) |
|
| 50 | - { |
|
| 51 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * finds and sets the \EE_Event object for use throughout class |
|
| 58 | - * |
|
| 59 | - * @param mixed $event |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - protected function setEvent( $event = null ) |
|
| 63 | - { |
|
| 64 | - if ( $event === null ) { |
|
| 65 | - global $post; |
|
| 66 | - $event = $post; |
|
| 67 | - } |
|
| 68 | - if ( $event instanceof \EE_Event ) { |
|
| 69 | - $this->event = $event; |
|
| 70 | - } else if ( $event instanceof \WP_Post ) { |
|
| 71 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof \EE_Event ) { |
|
| 72 | - $this->event = $event->EE_Event; |
|
| 73 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 74 | - $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 75 | - $this->event = $event->EE_Event; |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 79 | - $dev_msg = $user_msg . __( |
|
| 80 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 81 | - 'event_espresso' |
|
| 82 | - ); |
|
| 83 | - \EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - return true; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function getMaxAttendees() |
|
| 95 | - { |
|
| 96 | - return $this->max_attendees; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param int $max_attendees |
|
| 103 | - */ |
|
| 104 | - public function setMaxAttendees( $max_attendees ) |
|
| 105 | - { |
|
| 106 | - $this->max_attendees = absint( $max_attendees ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * creates buttons for selecting number of attendees for an event |
|
| 113 | - * |
|
| 114 | - * @param \WP_Post|int $event |
|
| 115 | - * @param bool $view_details |
|
| 116 | - * @return string |
|
| 117 | - * @throws \EE_Error |
|
| 118 | - */ |
|
| 119 | - public function display( $event = null, $view_details = false ) |
|
| 120 | - { |
|
| 121 | - // reset filter for displaying submit button |
|
| 122 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 123 | - // poke and prod incoming event till it tells us what it is |
|
| 124 | - if ( ! $this->setEvent( $event ) ) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - if ( apply_filters( 'FHEE__EED_Events_Archive__event_list_iframe', false ) ) { |
|
| 128 | - $this->setIframe(); |
|
| 129 | - } |
|
| 130 | - $event_post = $this->event instanceof \EE_Event ? $this->event->ID() : $event; |
|
| 131 | - // grab event status |
|
| 132 | - $_event_active_status = $this->event->get_active_status(); |
|
| 133 | - if ( |
|
| 134 | - ! is_admin() |
|
| 135 | - && ( |
|
| 136 | - ! $this->event->display_ticket_selector() |
|
| 137 | - || $view_details |
|
| 138 | - || post_password_required( $event_post ) |
|
| 139 | - || ( |
|
| 140 | - $_event_active_status !== \EE_Datetime::active |
|
| 141 | - && $_event_active_status !== \EE_Datetime::upcoming |
|
| 142 | - && $_event_active_status !== \EE_Datetime::sold_out |
|
| 143 | - && ! ( |
|
| 144 | - $_event_active_status === \EE_Datetime::inactive |
|
| 145 | - && is_user_logged_in() |
|
| 146 | - ) |
|
| 147 | - ) |
|
| 148 | - ) |
|
| 149 | - ) { |
|
| 150 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 151 | - } |
|
| 152 | - $template_args = array(); |
|
| 153 | - $template_args[ 'event_status' ] = $_event_active_status; |
|
| 154 | - $template_args[ 'date_format' ] = apply_filters( |
|
| 155 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 156 | - get_option( 'date_format' ) |
|
| 157 | - ); |
|
| 158 | - $template_args[ 'time_format' ] = apply_filters( |
|
| 159 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 160 | - get_option( 'time_format' ) |
|
| 161 | - ); |
|
| 162 | - $template_args[ 'EVT_ID' ] = $this->event->ID(); |
|
| 163 | - $template_args[ 'event' ] = $this->event; |
|
| 164 | - // is the event expired ? |
|
| 165 | - $template_args[ 'event_is_expired' ] = $this->event->is_expired(); |
|
| 166 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 167 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 168 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 169 | - 'event_espresso' |
|
| 170 | - ) . '</span></div>'; |
|
| 171 | - } |
|
| 172 | - $ticket_query_args = array( |
|
| 173 | - array( 'Datetime.EVT_ID' => $this->event->ID() ), |
|
| 174 | - 'order_by' => array( |
|
| 175 | - 'TKT_order' => 'ASC', |
|
| 176 | - 'TKT_required' => 'DESC', |
|
| 177 | - 'TKT_start_date' => 'ASC', |
|
| 178 | - 'TKT_end_date' => 'ASC', |
|
| 179 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 180 | - ), |
|
| 181 | - ); |
|
| 182 | - if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets ) { |
|
| 183 | - //use the correct applicable time query depending on what version of core is being run. |
|
| 184 | - $current_time = method_exists( 'EEM_Datetime', 'current_time_for_query' ) |
|
| 185 | - ? time() |
|
| 186 | - : current_time( 'timestamp' ); |
|
| 187 | - $ticket_query_args[ 0 ][ 'TKT_end_date' ] = array( '>', $current_time ); |
|
| 188 | - } |
|
| 189 | - // get all tickets for this event ordered by the datetime |
|
| 190 | - $template_args[ 'tickets' ] = \EEM_Ticket::instance()->get_all( $ticket_query_args ); |
|
| 191 | - if ( count( $template_args[ 'tickets' ] ) < 1 ) { |
|
| 192 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 193 | - 'We\'re sorry, but all ticket sales have ended.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ) . '</span></div>'; |
|
| 196 | - } |
|
| 197 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 198 | - $this->setMaxAttendees( |
|
| 199 | - apply_filters( |
|
| 200 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 201 | - $this->event->additional_limit() |
|
| 202 | - ) |
|
| 203 | - ); |
|
| 204 | - $template_args[ 'max_atndz' ] = $this->getMaxAttendees(); |
|
| 205 | - if ( $template_args[ 'max_atndz' ] < 1 ) { |
|
| 206 | - $sales_closed_msg = __( |
|
| 207 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 208 | - 'event_espresso' |
|
| 209 | - ); |
|
| 210 | - if ( current_user_can( 'edit_post', $this->event->ID() ) ) { |
|
| 211 | - $link = get_edit_post_link( $this->event->ID() ); |
|
| 212 | - $sales_closed_msg .= sprintf( |
|
| 213 | - __( |
|
| 214 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 215 | - 'event_espresso' |
|
| 216 | - ), |
|
| 217 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 218 | - '</b><br />', |
|
| 219 | - $link = '<span class="edit-link"><a class="post-edit-link" href="' . $link . '">', |
|
| 220 | - '</a></span></div>' |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 224 | - } |
|
| 225 | - $templates[ 'ticket_selector' ] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
| 226 | - $templates[ 'ticket_selector' ] = apply_filters( |
|
| 227 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
| 228 | - $templates[ 'ticket_selector' ], |
|
| 229 | - $this->event |
|
| 230 | - ); |
|
| 231 | - // redirecting to another site for registration ?? |
|
| 232 | - $external_url = $this->event->external_url() !== null || $this->event->external_url() !== '' |
|
| 233 | - ? $this->event->external_url() |
|
| 234 | - : ''; |
|
| 235 | - // if not redirecting to another site for registration |
|
| 236 | - if ( ! $external_url ) { |
|
| 237 | - // then display the ticket selector |
|
| 238 | - $ticket_selector = \EEH_Template::locate_template( $templates[ 'ticket_selector' ], $template_args ); |
|
| 239 | - } else { |
|
| 240 | - // if not we still need to trigger the display of the submit button |
|
| 241 | - add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 242 | - //display notice to admin that registration is external |
|
| 243 | - $ticket_selector = ! is_admin() |
|
| 244 | - ? '' |
|
| 245 | - : __( |
|
| 246 | - 'Registration is at an external URL for this event.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - $ticket_selector = ! is_admin() |
|
| 251 | - ? $this->formOpen( |
|
| 252 | - $this->event->ID(), |
|
| 253 | - $external_url |
|
| 254 | - ) . $ticket_selector |
|
| 255 | - : $ticket_selector; |
|
| 256 | - // now set up the form (but not for the admin) |
|
| 257 | - // submit button and form close tag |
|
| 258 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton() : ''; |
|
| 259 | - // set no cache headers and constants |
|
| 260 | - \EE_System::do_not_cache(); |
|
| 261 | - return $ticket_selector; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * formOpen |
|
| 268 | - * |
|
| 269 | - * @param int $ID |
|
| 270 | - * @param string $external_url |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 274 | - { |
|
| 275 | - // if redirecting, we don't need any anything else |
|
| 276 | - if ( $external_url ) { |
|
| 277 | - $html = '<form method="GET" action="' . \EEH_URL::refactor_url($external_url) . '"'; |
|
| 278 | - // open link in new window ? |
|
| 279 | - $html .= apply_filters( |
|
| 280 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 281 | - false |
|
| 282 | - ) |
|
| 283 | - ? ' target="_blank"' |
|
| 284 | - : ''; |
|
| 285 | - $html .= '>'; |
|
| 286 | - $query_args = \EEH_URL::get_query_string( $external_url ); |
|
| 287 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 288 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 289 | - } |
|
| 290 | - return $html; |
|
| 291 | - } |
|
| 292 | - // if this is a "Dude Where's my Ticket Selector?" ( DWMTS ) type event( ie: $_max_atndz === 1), |
|
| 293 | - // and its the event list, and there is no submit button, then don't start building a form |
|
| 294 | - // because the "View Details" button will build its own form |
|
| 295 | - if ( |
|
| 296 | - $this->getMaxAttendees() === 1 |
|
| 297 | - && is_archive() |
|
| 298 | - && ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false) |
|
| 299 | - ) { |
|
| 300 | - return ''; |
|
| 301 | - } |
|
| 302 | - $checkout_url = \EEH_Event_View::event_link_url( $ID ); |
|
| 303 | - if ( ! $checkout_url ) { |
|
| 304 | - \EE_Error::add_error( |
|
| 305 | - __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 306 | - __FILE__, |
|
| 307 | - __FUNCTION__, |
|
| 308 | - __LINE__ |
|
| 309 | - ); |
|
| 310 | - } |
|
| 311 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 312 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 313 | - $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false ); |
|
| 314 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 315 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 316 | - return $html; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * displaySubmitButton |
|
| 323 | - * |
|
| 324 | - * @access public |
|
| 325 | - * @return string |
|
| 326 | - * @throws \EE_Error |
|
| 327 | - */ |
|
| 328 | - public function displaySubmitButton() |
|
| 329 | - { |
|
| 330 | - $html = ''; |
|
| 331 | - if ( ! is_admin() ) { |
|
| 332 | - // standard TS displayed with submit button, ie: "Register Now" |
|
| 333 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 334 | - $html .= $this->displayRegisterNowButton(); |
|
| 335 | - $html .= empty($external_url) |
|
| 336 | - ? $this->ticketSelectorEndDiv() |
|
| 337 | - : $this->clearTicketSelector(); |
|
| 338 | - $html .= '<br/>' . $this->formClose(); |
|
| 339 | - } else if ($this->getMaxAttendees() === 1 ) { |
|
| 340 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 341 | - if ( $this->event->is_sold_out() ) { |
|
| 342 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 343 | - $html .= apply_filters( |
|
| 344 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 345 | - sprintf( |
|
| 346 | - __( |
|
| 347 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ), |
|
| 350 | - '<p class="no-ticket-selector-msg clear-float">', |
|
| 351 | - $this->event->name(), |
|
| 352 | - '</p>', |
|
| 353 | - '<br />' |
|
| 354 | - ), |
|
| 355 | - $this->event |
|
| 356 | - ); |
|
| 357 | - if ( |
|
| 358 | - apply_filters( |
|
| 359 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 360 | - false, |
|
| 361 | - $this->event |
|
| 362 | - ) |
|
| 363 | - ) { |
|
| 364 | - $html .= $this->displayRegisterNowButton(); |
|
| 365 | - } |
|
| 366 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 367 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 368 | - } else if ( |
|
| 369 | - apply_filters( 'FHEE__EE_Ticket_Selector__hide_ticket_selector', false ) |
|
| 370 | - && ! is_single() |
|
| 371 | - ) { |
|
| 372 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 373 | - // but no tickets are available, so display event's "View Details" button. |
|
| 374 | - // it is being viewed via somewhere other than a single post |
|
| 375 | - $html .= $this->displayViewDetailsButton(true); |
|
| 376 | - } |
|
| 377 | - } else if ( is_archive() ) { |
|
| 378 | - // event list, no tickets available so display event's "View Details" button |
|
| 379 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 380 | - $html .= $this->displayViewDetailsButton(); |
|
| 381 | - } else { |
|
| 382 | - if ( |
|
| 383 | - apply_filters( |
|
| 384 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 385 | - false, |
|
| 386 | - $this->event |
|
| 387 | - ) |
|
| 388 | - ) { |
|
| 389 | - $html .= $this->displayRegisterNowButton(); |
|
| 390 | - } |
|
| 391 | - // no submit or view details button, and no additional content |
|
| 392 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 393 | - } |
|
| 394 | - if ( ! $this->iframe && ! is_archive() ) { |
|
| 395 | - $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - return $html; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @return string |
|
| 405 | - * @throws \EE_Error |
|
| 406 | - */ |
|
| 407 | - public function displayRegisterNowButton() |
|
| 408 | - { |
|
| 409 | - $btn_text = apply_filters( |
|
| 410 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 411 | - __('Register Now', 'event_espresso'), |
|
| 412 | - $this->event |
|
| 413 | - ); |
|
| 414 | - $external_url = $this->event->external_url(); |
|
| 415 | - $html = '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 416 | - $html .= ' class="ticket-selector-submit-btn '; |
|
| 417 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 418 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 419 | - $html .= apply_filters( |
|
| 420 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 421 | - '', |
|
| 422 | - $this->event |
|
| 423 | - ); |
|
| 424 | - return $html; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * displayViewDetailsButton |
|
| 431 | - * |
|
| 432 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 433 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 434 | - * either because they are sold out, expired, or not yet on sale. |
|
| 435 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
| 436 | - * @return string |
|
| 437 | - * @throws \EE_Error |
|
| 438 | - */ |
|
| 439 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 440 | - { |
|
| 441 | - if ( ! $this->event->get_permalink() ) { |
|
| 442 | - \EE_Error::add_error( |
|
| 443 | - __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 444 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 445 | - ); |
|
| 446 | - } |
|
| 447 | - $view_details_btn = '<form method="POST" action="' |
|
| 448 | - . apply_filters( |
|
| 449 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 450 | - $this->event->get_permalink(), |
|
| 451 | - $this->event |
|
| 452 | - ) |
|
| 453 | - . '"'; |
|
| 454 | - $view_details_btn .= $this->iframe ? ' target="_blank"' : ''; |
|
| 455 | - $view_details_btn .= '>'; |
|
| 456 | - $btn_text = apply_filters( |
|
| 457 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 458 | - __( 'View Details', 'event_espresso' ), |
|
| 459 | - $this->event |
|
| 460 | - ); |
|
| 461 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 462 | - . $this->event->ID() |
|
| 463 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 464 | - . $btn_text |
|
| 465 | - . '" />'; |
|
| 466 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 467 | - if ( $DWMTS ) { |
|
| 468 | - $view_details_btn .= $this->formClose(); |
|
| 469 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 470 | - $view_details_btn .= '<br/>'; |
|
| 471 | - } else { |
|
| 472 | - $view_details_btn .= $this->clearTicketSelector(); |
|
| 473 | - $view_details_btn .= '<br/>'; |
|
| 474 | - $view_details_btn .= $this->formClose(); |
|
| 475 | - } |
|
| 476 | - return $view_details_btn; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @return string |
|
| 483 | - */ |
|
| 484 | - public function ticketSelectorEndDiv() |
|
| 485 | - { |
|
| 486 | - return '<div class="clear"></div></div>'; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function clearTicketSelector() |
|
| 495 | - { |
|
| 496 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 497 | - return '<div class="clear"></div>'; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * @access public |
|
| 504 | - * @return string |
|
| 505 | - */ |
|
| 506 | - public function formClose() |
|
| 507 | - { |
|
| 508 | - return '</form>'; |
|
| 509 | - } |
|
| 22 | + /** |
|
| 23 | + * event that ticket selector is being generated for |
|
| 24 | + * |
|
| 25 | + * @access protected |
|
| 26 | + * @var \EE_Event $event |
|
| 27 | + */ |
|
| 28 | + protected $event; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
| 32 | + * |
|
| 33 | + * @var bool $iframe |
|
| 34 | + */ |
|
| 35 | + protected $iframe = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * max attendees that can register for event at one time |
|
| 39 | + * |
|
| 40 | + * @var int $max_attendees |
|
| 41 | + */ |
|
| 42 | + private $max_attendees = EE_INF; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param boolean $iframe |
|
| 48 | + */ |
|
| 49 | + public function setIframe( $iframe = true ) |
|
| 50 | + { |
|
| 51 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * finds and sets the \EE_Event object for use throughout class |
|
| 58 | + * |
|
| 59 | + * @param mixed $event |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + protected function setEvent( $event = null ) |
|
| 63 | + { |
|
| 64 | + if ( $event === null ) { |
|
| 65 | + global $post; |
|
| 66 | + $event = $post; |
|
| 67 | + } |
|
| 68 | + if ( $event instanceof \EE_Event ) { |
|
| 69 | + $this->event = $event; |
|
| 70 | + } else if ( $event instanceof \WP_Post ) { |
|
| 71 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof \EE_Event ) { |
|
| 72 | + $this->event = $event->EE_Event; |
|
| 73 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
| 74 | + $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 75 | + $this->event = $event->EE_Event; |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 79 | + $dev_msg = $user_msg . __( |
|
| 80 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 81 | + 'event_espresso' |
|
| 82 | + ); |
|
| 83 | + \EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + return true; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function getMaxAttendees() |
|
| 95 | + { |
|
| 96 | + return $this->max_attendees; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param int $max_attendees |
|
| 103 | + */ |
|
| 104 | + public function setMaxAttendees( $max_attendees ) |
|
| 105 | + { |
|
| 106 | + $this->max_attendees = absint( $max_attendees ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * creates buttons for selecting number of attendees for an event |
|
| 113 | + * |
|
| 114 | + * @param \WP_Post|int $event |
|
| 115 | + * @param bool $view_details |
|
| 116 | + * @return string |
|
| 117 | + * @throws \EE_Error |
|
| 118 | + */ |
|
| 119 | + public function display( $event = null, $view_details = false ) |
|
| 120 | + { |
|
| 121 | + // reset filter for displaying submit button |
|
| 122 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 123 | + // poke and prod incoming event till it tells us what it is |
|
| 124 | + if ( ! $this->setEvent( $event ) ) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + if ( apply_filters( 'FHEE__EED_Events_Archive__event_list_iframe', false ) ) { |
|
| 128 | + $this->setIframe(); |
|
| 129 | + } |
|
| 130 | + $event_post = $this->event instanceof \EE_Event ? $this->event->ID() : $event; |
|
| 131 | + // grab event status |
|
| 132 | + $_event_active_status = $this->event->get_active_status(); |
|
| 133 | + if ( |
|
| 134 | + ! is_admin() |
|
| 135 | + && ( |
|
| 136 | + ! $this->event->display_ticket_selector() |
|
| 137 | + || $view_details |
|
| 138 | + || post_password_required( $event_post ) |
|
| 139 | + || ( |
|
| 140 | + $_event_active_status !== \EE_Datetime::active |
|
| 141 | + && $_event_active_status !== \EE_Datetime::upcoming |
|
| 142 | + && $_event_active_status !== \EE_Datetime::sold_out |
|
| 143 | + && ! ( |
|
| 144 | + $_event_active_status === \EE_Datetime::inactive |
|
| 145 | + && is_user_logged_in() |
|
| 146 | + ) |
|
| 147 | + ) |
|
| 148 | + ) |
|
| 149 | + ) { |
|
| 150 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 151 | + } |
|
| 152 | + $template_args = array(); |
|
| 153 | + $template_args[ 'event_status' ] = $_event_active_status; |
|
| 154 | + $template_args[ 'date_format' ] = apply_filters( |
|
| 155 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 156 | + get_option( 'date_format' ) |
|
| 157 | + ); |
|
| 158 | + $template_args[ 'time_format' ] = apply_filters( |
|
| 159 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 160 | + get_option( 'time_format' ) |
|
| 161 | + ); |
|
| 162 | + $template_args[ 'EVT_ID' ] = $this->event->ID(); |
|
| 163 | + $template_args[ 'event' ] = $this->event; |
|
| 164 | + // is the event expired ? |
|
| 165 | + $template_args[ 'event_is_expired' ] = $this->event->is_expired(); |
|
| 166 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
| 167 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 168 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 169 | + 'event_espresso' |
|
| 170 | + ) . '</span></div>'; |
|
| 171 | + } |
|
| 172 | + $ticket_query_args = array( |
|
| 173 | + array( 'Datetime.EVT_ID' => $this->event->ID() ), |
|
| 174 | + 'order_by' => array( |
|
| 175 | + 'TKT_order' => 'ASC', |
|
| 176 | + 'TKT_required' => 'DESC', |
|
| 177 | + 'TKT_start_date' => 'ASC', |
|
| 178 | + 'TKT_end_date' => 'ASC', |
|
| 179 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 180 | + ), |
|
| 181 | + ); |
|
| 182 | + if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets ) { |
|
| 183 | + //use the correct applicable time query depending on what version of core is being run. |
|
| 184 | + $current_time = method_exists( 'EEM_Datetime', 'current_time_for_query' ) |
|
| 185 | + ? time() |
|
| 186 | + : current_time( 'timestamp' ); |
|
| 187 | + $ticket_query_args[ 0 ][ 'TKT_end_date' ] = array( '>', $current_time ); |
|
| 188 | + } |
|
| 189 | + // get all tickets for this event ordered by the datetime |
|
| 190 | + $template_args[ 'tickets' ] = \EEM_Ticket::instance()->get_all( $ticket_query_args ); |
|
| 191 | + if ( count( $template_args[ 'tickets' ] ) < 1 ) { |
|
| 192 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 193 | + 'We\'re sorry, but all ticket sales have ended.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ) . '</span></div>'; |
|
| 196 | + } |
|
| 197 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 198 | + $this->setMaxAttendees( |
|
| 199 | + apply_filters( |
|
| 200 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 201 | + $this->event->additional_limit() |
|
| 202 | + ) |
|
| 203 | + ); |
|
| 204 | + $template_args[ 'max_atndz' ] = $this->getMaxAttendees(); |
|
| 205 | + if ( $template_args[ 'max_atndz' ] < 1 ) { |
|
| 206 | + $sales_closed_msg = __( |
|
| 207 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 208 | + 'event_espresso' |
|
| 209 | + ); |
|
| 210 | + if ( current_user_can( 'edit_post', $this->event->ID() ) ) { |
|
| 211 | + $link = get_edit_post_link( $this->event->ID() ); |
|
| 212 | + $sales_closed_msg .= sprintf( |
|
| 213 | + __( |
|
| 214 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 215 | + 'event_espresso' |
|
| 216 | + ), |
|
| 217 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 218 | + '</b><br />', |
|
| 219 | + $link = '<span class="edit-link"><a class="post-edit-link" href="' . $link . '">', |
|
| 220 | + '</a></span></div>' |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 224 | + } |
|
| 225 | + $templates[ 'ticket_selector' ] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
| 226 | + $templates[ 'ticket_selector' ] = apply_filters( |
|
| 227 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
| 228 | + $templates[ 'ticket_selector' ], |
|
| 229 | + $this->event |
|
| 230 | + ); |
|
| 231 | + // redirecting to another site for registration ?? |
|
| 232 | + $external_url = $this->event->external_url() !== null || $this->event->external_url() !== '' |
|
| 233 | + ? $this->event->external_url() |
|
| 234 | + : ''; |
|
| 235 | + // if not redirecting to another site for registration |
|
| 236 | + if ( ! $external_url ) { |
|
| 237 | + // then display the ticket selector |
|
| 238 | + $ticket_selector = \EEH_Template::locate_template( $templates[ 'ticket_selector' ], $template_args ); |
|
| 239 | + } else { |
|
| 240 | + // if not we still need to trigger the display of the submit button |
|
| 241 | + add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 242 | + //display notice to admin that registration is external |
|
| 243 | + $ticket_selector = ! is_admin() |
|
| 244 | + ? '' |
|
| 245 | + : __( |
|
| 246 | + 'Registration is at an external URL for this event.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + $ticket_selector = ! is_admin() |
|
| 251 | + ? $this->formOpen( |
|
| 252 | + $this->event->ID(), |
|
| 253 | + $external_url |
|
| 254 | + ) . $ticket_selector |
|
| 255 | + : $ticket_selector; |
|
| 256 | + // now set up the form (but not for the admin) |
|
| 257 | + // submit button and form close tag |
|
| 258 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton() : ''; |
|
| 259 | + // set no cache headers and constants |
|
| 260 | + \EE_System::do_not_cache(); |
|
| 261 | + return $ticket_selector; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * formOpen |
|
| 268 | + * |
|
| 269 | + * @param int $ID |
|
| 270 | + * @param string $external_url |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
| 274 | + { |
|
| 275 | + // if redirecting, we don't need any anything else |
|
| 276 | + if ( $external_url ) { |
|
| 277 | + $html = '<form method="GET" action="' . \EEH_URL::refactor_url($external_url) . '"'; |
|
| 278 | + // open link in new window ? |
|
| 279 | + $html .= apply_filters( |
|
| 280 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 281 | + false |
|
| 282 | + ) |
|
| 283 | + ? ' target="_blank"' |
|
| 284 | + : ''; |
|
| 285 | + $html .= '>'; |
|
| 286 | + $query_args = \EEH_URL::get_query_string( $external_url ); |
|
| 287 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 288 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 289 | + } |
|
| 290 | + return $html; |
|
| 291 | + } |
|
| 292 | + // if this is a "Dude Where's my Ticket Selector?" ( DWMTS ) type event( ie: $_max_atndz === 1), |
|
| 293 | + // and its the event list, and there is no submit button, then don't start building a form |
|
| 294 | + // because the "View Details" button will build its own form |
|
| 295 | + if ( |
|
| 296 | + $this->getMaxAttendees() === 1 |
|
| 297 | + && is_archive() |
|
| 298 | + && ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false) |
|
| 299 | + ) { |
|
| 300 | + return ''; |
|
| 301 | + } |
|
| 302 | + $checkout_url = \EEH_Event_View::event_link_url( $ID ); |
|
| 303 | + if ( ! $checkout_url ) { |
|
| 304 | + \EE_Error::add_error( |
|
| 305 | + __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 306 | + __FILE__, |
|
| 307 | + __FUNCTION__, |
|
| 308 | + __LINE__ |
|
| 309 | + ); |
|
| 310 | + } |
|
| 311 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 312 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 313 | + $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false ); |
|
| 314 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 315 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 316 | + return $html; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * displaySubmitButton |
|
| 323 | + * |
|
| 324 | + * @access public |
|
| 325 | + * @return string |
|
| 326 | + * @throws \EE_Error |
|
| 327 | + */ |
|
| 328 | + public function displaySubmitButton() |
|
| 329 | + { |
|
| 330 | + $html = ''; |
|
| 331 | + if ( ! is_admin() ) { |
|
| 332 | + // standard TS displayed with submit button, ie: "Register Now" |
|
| 333 | + if ( apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 334 | + $html .= $this->displayRegisterNowButton(); |
|
| 335 | + $html .= empty($external_url) |
|
| 336 | + ? $this->ticketSelectorEndDiv() |
|
| 337 | + : $this->clearTicketSelector(); |
|
| 338 | + $html .= '<br/>' . $this->formClose(); |
|
| 339 | + } else if ($this->getMaxAttendees() === 1 ) { |
|
| 340 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 341 | + if ( $this->event->is_sold_out() ) { |
|
| 342 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 343 | + $html .= apply_filters( |
|
| 344 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 345 | + sprintf( |
|
| 346 | + __( |
|
| 347 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ), |
|
| 350 | + '<p class="no-ticket-selector-msg clear-float">', |
|
| 351 | + $this->event->name(), |
|
| 352 | + '</p>', |
|
| 353 | + '<br />' |
|
| 354 | + ), |
|
| 355 | + $this->event |
|
| 356 | + ); |
|
| 357 | + if ( |
|
| 358 | + apply_filters( |
|
| 359 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 360 | + false, |
|
| 361 | + $this->event |
|
| 362 | + ) |
|
| 363 | + ) { |
|
| 364 | + $html .= $this->displayRegisterNowButton(); |
|
| 365 | + } |
|
| 366 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 367 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 368 | + } else if ( |
|
| 369 | + apply_filters( 'FHEE__EE_Ticket_Selector__hide_ticket_selector', false ) |
|
| 370 | + && ! is_single() |
|
| 371 | + ) { |
|
| 372 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 373 | + // but no tickets are available, so display event's "View Details" button. |
|
| 374 | + // it is being viewed via somewhere other than a single post |
|
| 375 | + $html .= $this->displayViewDetailsButton(true); |
|
| 376 | + } |
|
| 377 | + } else if ( is_archive() ) { |
|
| 378 | + // event list, no tickets available so display event's "View Details" button |
|
| 379 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 380 | + $html .= $this->displayViewDetailsButton(); |
|
| 381 | + } else { |
|
| 382 | + if ( |
|
| 383 | + apply_filters( |
|
| 384 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 385 | + false, |
|
| 386 | + $this->event |
|
| 387 | + ) |
|
| 388 | + ) { |
|
| 389 | + $html .= $this->displayRegisterNowButton(); |
|
| 390 | + } |
|
| 391 | + // no submit or view details button, and no additional content |
|
| 392 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 393 | + } |
|
| 394 | + if ( ! $this->iframe && ! is_archive() ) { |
|
| 395 | + $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + return $html; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @return string |
|
| 405 | + * @throws \EE_Error |
|
| 406 | + */ |
|
| 407 | + public function displayRegisterNowButton() |
|
| 408 | + { |
|
| 409 | + $btn_text = apply_filters( |
|
| 410 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 411 | + __('Register Now', 'event_espresso'), |
|
| 412 | + $this->event |
|
| 413 | + ); |
|
| 414 | + $external_url = $this->event->external_url(); |
|
| 415 | + $html = '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 416 | + $html .= ' class="ticket-selector-submit-btn '; |
|
| 417 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 418 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 419 | + $html .= apply_filters( |
|
| 420 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 421 | + '', |
|
| 422 | + $this->event |
|
| 423 | + ); |
|
| 424 | + return $html; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * displayViewDetailsButton |
|
| 431 | + * |
|
| 432 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 433 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 434 | + * either because they are sold out, expired, or not yet on sale. |
|
| 435 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
| 436 | + * @return string |
|
| 437 | + * @throws \EE_Error |
|
| 438 | + */ |
|
| 439 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
| 440 | + { |
|
| 441 | + if ( ! $this->event->get_permalink() ) { |
|
| 442 | + \EE_Error::add_error( |
|
| 443 | + __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 444 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 445 | + ); |
|
| 446 | + } |
|
| 447 | + $view_details_btn = '<form method="POST" action="' |
|
| 448 | + . apply_filters( |
|
| 449 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 450 | + $this->event->get_permalink(), |
|
| 451 | + $this->event |
|
| 452 | + ) |
|
| 453 | + . '"'; |
|
| 454 | + $view_details_btn .= $this->iframe ? ' target="_blank"' : ''; |
|
| 455 | + $view_details_btn .= '>'; |
|
| 456 | + $btn_text = apply_filters( |
|
| 457 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 458 | + __( 'View Details', 'event_espresso' ), |
|
| 459 | + $this->event |
|
| 460 | + ); |
|
| 461 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 462 | + . $this->event->ID() |
|
| 463 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 464 | + . $btn_text |
|
| 465 | + . '" />'; |
|
| 466 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 467 | + if ( $DWMTS ) { |
|
| 468 | + $view_details_btn .= $this->formClose(); |
|
| 469 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 470 | + $view_details_btn .= '<br/>'; |
|
| 471 | + } else { |
|
| 472 | + $view_details_btn .= $this->clearTicketSelector(); |
|
| 473 | + $view_details_btn .= '<br/>'; |
|
| 474 | + $view_details_btn .= $this->formClose(); |
|
| 475 | + } |
|
| 476 | + return $view_details_btn; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return string |
|
| 483 | + */ |
|
| 484 | + public function ticketSelectorEndDiv() |
|
| 485 | + { |
|
| 486 | + return '<div class="clear"></div></div>'; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function clearTicketSelector() |
|
| 495 | + { |
|
| 496 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 497 | + return '<div class="clear"></div>'; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * @access public |
|
| 504 | + * @return string |
|
| 505 | + */ |
|
| 506 | + public function formClose() |
|
| 507 | + { |
|
| 508 | + return '</form>'; |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | 511 | |
| 512 | 512 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @param boolean $iframe |
| 48 | 48 | */ |
| 49 | - public function setIframe( $iframe = true ) |
|
| 49 | + public function setIframe($iframe = true) |
|
| 50 | 50 | { |
| 51 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 51 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -59,28 +59,28 @@ discard block |
||
| 59 | 59 | * @param mixed $event |
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | - protected function setEvent( $event = null ) |
|
| 62 | + protected function setEvent($event = null) |
|
| 63 | 63 | { |
| 64 | - if ( $event === null ) { |
|
| 64 | + if ($event === null) { |
|
| 65 | 65 | global $post; |
| 66 | 66 | $event = $post; |
| 67 | 67 | } |
| 68 | - if ( $event instanceof \EE_Event ) { |
|
| 68 | + if ($event instanceof \EE_Event) { |
|
| 69 | 69 | $this->event = $event; |
| 70 | - } else if ( $event instanceof \WP_Post ) { |
|
| 71 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof \EE_Event ) { |
|
| 70 | + } else if ($event instanceof \WP_Post) { |
|
| 71 | + if (isset($event->EE_Event) && $event->EE_Event instanceof \EE_Event) { |
|
| 72 | 72 | $this->event = $event->EE_Event; |
| 73 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 74 | - $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 73 | + } else if ($event->post_type === 'espresso_events') { |
|
| 74 | + $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
| 75 | 75 | $this->event = $event->EE_Event; |
| 76 | 76 | } |
| 77 | 77 | } else { |
| 78 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 79 | - $dev_msg = $user_msg . __( |
|
| 78 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
| 79 | + $dev_msg = $user_msg.__( |
|
| 80 | 80 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
| 81 | 81 | 'event_espresso' |
| 82 | 82 | ); |
| 83 | - \EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 83 | + \EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | return true; |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * @param int $max_attendees |
| 103 | 103 | */ |
| 104 | - public function setMaxAttendees( $max_attendees ) |
|
| 104 | + public function setMaxAttendees($max_attendees) |
|
| 105 | 105 | { |
| 106 | - $this->max_attendees = absint( $max_attendees ); |
|
| 106 | + $this->max_attendees = absint($max_attendees); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | * @return string |
| 117 | 117 | * @throws \EE_Error |
| 118 | 118 | */ |
| 119 | - public function display( $event = null, $view_details = false ) |
|
| 119 | + public function display($event = null, $view_details = false) |
|
| 120 | 120 | { |
| 121 | 121 | // reset filter for displaying submit button |
| 122 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 122 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 123 | 123 | // poke and prod incoming event till it tells us what it is |
| 124 | - if ( ! $this->setEvent( $event ) ) { |
|
| 124 | + if ( ! $this->setEvent($event)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | - if ( apply_filters( 'FHEE__EED_Events_Archive__event_list_iframe', false ) ) { |
|
| 127 | + if (apply_filters('FHEE__EED_Events_Archive__event_list_iframe', false)) { |
|
| 128 | 128 | $this->setIframe(); |
| 129 | 129 | } |
| 130 | 130 | $event_post = $this->event instanceof \EE_Event ? $this->event->ID() : $event; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | && ( |
| 136 | 136 | ! $this->event->display_ticket_selector() |
| 137 | 137 | || $view_details |
| 138 | - || post_password_required( $event_post ) |
|
| 138 | + || post_password_required($event_post) |
|
| 139 | 139 | || ( |
| 140 | 140 | $_event_active_status !== \EE_Datetime::active |
| 141 | 141 | && $_event_active_status !== \EE_Datetime::upcoming |
@@ -150,27 +150,27 @@ discard block |
||
| 150 | 150 | return ! is_single() ? $this->displayViewDetailsButton() : ''; |
| 151 | 151 | } |
| 152 | 152 | $template_args = array(); |
| 153 | - $template_args[ 'event_status' ] = $_event_active_status; |
|
| 154 | - $template_args[ 'date_format' ] = apply_filters( |
|
| 153 | + $template_args['event_status'] = $_event_active_status; |
|
| 154 | + $template_args['date_format'] = apply_filters( |
|
| 155 | 155 | 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
| 156 | - get_option( 'date_format' ) |
|
| 156 | + get_option('date_format') |
|
| 157 | 157 | ); |
| 158 | - $template_args[ 'time_format' ] = apply_filters( |
|
| 158 | + $template_args['time_format'] = apply_filters( |
|
| 159 | 159 | 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
| 160 | - get_option( 'time_format' ) |
|
| 160 | + get_option('time_format') |
|
| 161 | 161 | ); |
| 162 | - $template_args[ 'EVT_ID' ] = $this->event->ID(); |
|
| 163 | - $template_args[ 'event' ] = $this->event; |
|
| 162 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
| 163 | + $template_args['event'] = $this->event; |
|
| 164 | 164 | // is the event expired ? |
| 165 | - $template_args[ 'event_is_expired' ] = $this->event->is_expired(); |
|
| 166 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 167 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 165 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 166 | + if ($template_args['event_is_expired']) { |
|
| 167 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.__( |
|
| 168 | 168 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
| 169 | 169 | 'event_espresso' |
| 170 | - ) . '</span></div>'; |
|
| 170 | + ).'</span></div>'; |
|
| 171 | 171 | } |
| 172 | 172 | $ticket_query_args = array( |
| 173 | - array( 'Datetime.EVT_ID' => $this->event->ID() ), |
|
| 173 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 174 | 174 | 'order_by' => array( |
| 175 | 175 | 'TKT_order' => 'ASC', |
| 176 | 176 | 'TKT_required' => 'DESC', |
@@ -179,20 +179,20 @@ discard block |
||
| 179 | 179 | 'Datetime.DTT_EVT_start' => 'DESC', |
| 180 | 180 | ), |
| 181 | 181 | ); |
| 182 | - if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets ) { |
|
| 182 | + if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
| 183 | 183 | //use the correct applicable time query depending on what version of core is being run. |
| 184 | - $current_time = method_exists( 'EEM_Datetime', 'current_time_for_query' ) |
|
| 184 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 185 | 185 | ? time() |
| 186 | - : current_time( 'timestamp' ); |
|
| 187 | - $ticket_query_args[ 0 ][ 'TKT_end_date' ] = array( '>', $current_time ); |
|
| 186 | + : current_time('timestamp'); |
|
| 187 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 188 | 188 | } |
| 189 | 189 | // get all tickets for this event ordered by the datetime |
| 190 | - $template_args[ 'tickets' ] = \EEM_Ticket::instance()->get_all( $ticket_query_args ); |
|
| 191 | - if ( count( $template_args[ 'tickets' ] ) < 1 ) { |
|
| 192 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( |
|
| 190 | + $template_args['tickets'] = \EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 191 | + if (count($template_args['tickets']) < 1) { |
|
| 192 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.__( |
|
| 193 | 193 | 'We\'re sorry, but all ticket sales have ended.', |
| 194 | 194 | 'event_espresso' |
| 195 | - ) . '</span></div>'; |
|
| 195 | + ).'</span></div>'; |
|
| 196 | 196 | } |
| 197 | 197 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
| 198 | 198 | $this->setMaxAttendees( |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | $this->event->additional_limit() |
| 202 | 202 | ) |
| 203 | 203 | ); |
| 204 | - $template_args[ 'max_atndz' ] = $this->getMaxAttendees(); |
|
| 205 | - if ( $template_args[ 'max_atndz' ] < 1 ) { |
|
| 204 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 205 | + if ($template_args['max_atndz'] < 1) { |
|
| 206 | 206 | $sales_closed_msg = __( |
| 207 | 207 | 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
| 208 | 208 | 'event_espresso' |
| 209 | 209 | ); |
| 210 | - if ( current_user_can( 'edit_post', $this->event->ID() ) ) { |
|
| 211 | - $link = get_edit_post_link( $this->event->ID() ); |
|
| 210 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 211 | + $link = get_edit_post_link($this->event->ID()); |
|
| 212 | 212 | $sales_closed_msg .= sprintf( |
| 213 | 213 | __( |
| 214 | 214 | '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
@@ -216,16 +216,16 @@ discard block |
||
| 216 | 216 | ), |
| 217 | 217 | '<div class="ee-attention" style="text-align: left;"><b>', |
| 218 | 218 | '</b><br />', |
| 219 | - $link = '<span class="edit-link"><a class="post-edit-link" href="' . $link . '">', |
|
| 219 | + $link = '<span class="edit-link"><a class="post-edit-link" href="'.$link.'">', |
|
| 220 | 220 | '</a></span></div>' |
| 221 | 221 | ); |
| 222 | 222 | } |
| 223 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 223 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
| 224 | 224 | } |
| 225 | - $templates[ 'ticket_selector' ] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
| 226 | - $templates[ 'ticket_selector' ] = apply_filters( |
|
| 225 | + $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart.template.php'; |
|
| 226 | + $templates['ticket_selector'] = apply_filters( |
|
| 227 | 227 | 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
| 228 | - $templates[ 'ticket_selector' ], |
|
| 228 | + $templates['ticket_selector'], |
|
| 229 | 229 | $this->event |
| 230 | 230 | ); |
| 231 | 231 | // redirecting to another site for registration ?? |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | ? $this->event->external_url() |
| 234 | 234 | : ''; |
| 235 | 235 | // if not redirecting to another site for registration |
| 236 | - if ( ! $external_url ) { |
|
| 236 | + if ( ! $external_url) { |
|
| 237 | 237 | // then display the ticket selector |
| 238 | - $ticket_selector = \EEH_Template::locate_template( $templates[ 'ticket_selector' ], $template_args ); |
|
| 238 | + $ticket_selector = \EEH_Template::locate_template($templates['ticket_selector'], $template_args); |
|
| 239 | 239 | } else { |
| 240 | 240 | // if not we still need to trigger the display of the submit button |
| 241 | - add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 241 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 242 | 242 | //display notice to admin that registration is external |
| 243 | 243 | $ticket_selector = ! is_admin() |
| 244 | 244 | ? '' |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | ? $this->formOpen( |
| 252 | 252 | $this->event->ID(), |
| 253 | 253 | $external_url |
| 254 | - ) . $ticket_selector |
|
| 254 | + ).$ticket_selector |
|
| 255 | 255 | : $ticket_selector; |
| 256 | 256 | // now set up the form (but not for the admin) |
| 257 | 257 | // submit button and form close tag |
@@ -270,11 +270,11 @@ discard block |
||
| 270 | 270 | * @param string $external_url |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 273 | + public function formOpen($ID = 0, $external_url = '') |
|
| 274 | 274 | { |
| 275 | 275 | // if redirecting, we don't need any anything else |
| 276 | - if ( $external_url ) { |
|
| 277 | - $html = '<form method="GET" action="' . \EEH_URL::refactor_url($external_url) . '"'; |
|
| 276 | + if ($external_url) { |
|
| 277 | + $html = '<form method="GET" action="'.\EEH_URL::refactor_url($external_url).'"'; |
|
| 278 | 278 | // open link in new window ? |
| 279 | 279 | $html .= apply_filters( |
| 280 | 280 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -283,9 +283,9 @@ discard block |
||
| 283 | 283 | ? ' target="_blank"' |
| 284 | 284 | : ''; |
| 285 | 285 | $html .= '>'; |
| 286 | - $query_args = \EEH_URL::get_query_string( $external_url ); |
|
| 287 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 288 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 286 | + $query_args = \EEH_URL::get_query_string($external_url); |
|
| 287 | + foreach ((array) $query_args as $query_arg => $value) { |
|
| 288 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
| 289 | 289 | } |
| 290 | 290 | return $html; |
| 291 | 291 | } |
@@ -299,20 +299,20 @@ discard block |
||
| 299 | 299 | ) { |
| 300 | 300 | return ''; |
| 301 | 301 | } |
| 302 | - $checkout_url = \EEH_Event_View::event_link_url( $ID ); |
|
| 303 | - if ( ! $checkout_url ) { |
|
| 302 | + $checkout_url = \EEH_Event_View::event_link_url($ID); |
|
| 303 | + if ( ! $checkout_url) { |
|
| 304 | 304 | \EE_Error::add_error( |
| 305 | - __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 305 | + __('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 306 | 306 | __FILE__, |
| 307 | 307 | __FUNCTION__, |
| 308 | 308 | __LINE__ |
| 309 | 309 | ); |
| 310 | 310 | } |
| 311 | 311 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
| 312 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 313 | - $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false ); |
|
| 312 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
| 313 | + $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false); |
|
| 314 | 314 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
| 315 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 315 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
| 316 | 316 | return $html; |
| 317 | 317 | } |
| 318 | 318 | |
@@ -328,17 +328,17 @@ discard block |
||
| 328 | 328 | public function displaySubmitButton() |
| 329 | 329 | { |
| 330 | 330 | $html = ''; |
| 331 | - if ( ! is_admin() ) { |
|
| 331 | + if ( ! is_admin()) { |
|
| 332 | 332 | // standard TS displayed with submit button, ie: "Register Now" |
| 333 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 333 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 334 | 334 | $html .= $this->displayRegisterNowButton(); |
| 335 | 335 | $html .= empty($external_url) |
| 336 | 336 | ? $this->ticketSelectorEndDiv() |
| 337 | 337 | : $this->clearTicketSelector(); |
| 338 | - $html .= '<br/>' . $this->formClose(); |
|
| 339 | - } else if ($this->getMaxAttendees() === 1 ) { |
|
| 338 | + $html .= '<br/>'.$this->formClose(); |
|
| 339 | + } else if ($this->getMaxAttendees() === 1) { |
|
| 340 | 340 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
| 341 | - if ( $this->event->is_sold_out() ) { |
|
| 341 | + if ($this->event->is_sold_out()) { |
|
| 342 | 342 | // then instead of a View Details or Submit button, just display a "Sold Out" message |
| 343 | 343 | $html .= apply_filters( |
| 344 | 344 | 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
| 367 | 367 | $html .= $this->ticketSelectorEndDiv(); |
| 368 | 368 | } else if ( |
| 369 | - apply_filters( 'FHEE__EE_Ticket_Selector__hide_ticket_selector', false ) |
|
| 369 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 370 | 370 | && ! is_single() |
| 371 | 371 | ) { |
| 372 | 372 | // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | // it is being viewed via somewhere other than a single post |
| 375 | 375 | $html .= $this->displayViewDetailsButton(true); |
| 376 | 376 | } |
| 377 | - } else if ( is_archive() ) { |
|
| 377 | + } else if (is_archive()) { |
|
| 378 | 378 | // event list, no tickets available so display event's "View Details" button |
| 379 | 379 | $html .= $this->ticketSelectorEndDiv(); |
| 380 | 380 | $html .= $this->displayViewDetailsButton(); |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | // no submit or view details button, and no additional content |
| 392 | 392 | $html .= $this->ticketSelectorEndDiv(); |
| 393 | 393 | } |
| 394 | - if ( ! $this->iframe && ! is_archive() ) { |
|
| 394 | + if ( ! $this->iframe && ! is_archive()) { |
|
| 395 | 395 | $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -412,10 +412,10 @@ discard block |
||
| 412 | 412 | $this->event |
| 413 | 413 | ); |
| 414 | 414 | $external_url = $this->event->external_url(); |
| 415 | - $html = '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 415 | + $html = '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
| 416 | 416 | $html .= ' class="ticket-selector-submit-btn '; |
| 417 | 417 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
| 418 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 418 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
| 419 | 419 | $html .= apply_filters( |
| 420 | 420 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
| 421 | 421 | '', |
@@ -436,11 +436,11 @@ discard block |
||
| 436 | 436 | * @return string |
| 437 | 437 | * @throws \EE_Error |
| 438 | 438 | */ |
| 439 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 439 | + public function displayViewDetailsButton($DWMTS = false) |
|
| 440 | 440 | { |
| 441 | - if ( ! $this->event->get_permalink() ) { |
|
| 441 | + if ( ! $this->event->get_permalink()) { |
|
| 442 | 442 | \EE_Error::add_error( |
| 443 | - __( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 443 | + __('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 444 | 444 | __FILE__, __FUNCTION__, __LINE__ |
| 445 | 445 | ); |
| 446 | 446 | } |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | $view_details_btn .= '>'; |
| 456 | 456 | $btn_text = apply_filters( |
| 457 | 457 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
| 458 | - __( 'View Details', 'event_espresso' ), |
|
| 458 | + __('View Details', 'event_espresso'), |
|
| 459 | 459 | $this->event |
| 460 | 460 | ); |
| 461 | 461 | $view_details_btn .= '<input id="ticket-selector-submit-' |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
| 464 | 464 | . $btn_text |
| 465 | 465 | . '" />'; |
| 466 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 467 | - if ( $DWMTS ) { |
|
| 466 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
| 467 | + if ($DWMTS) { |
|
| 468 | 468 | $view_details_btn .= $this->formClose(); |
| 469 | 469 | $view_details_btn .= $this->ticketSelectorEndDiv(); |
| 470 | 470 | $view_details_btn .= '<br/>'; |
@@ -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.27.rc.002'); |
|
| 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.27.rc.002'); |
|
| 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 | } |